Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx> --- help.c | 33 +++++++++++---------------------- 1 files changed, 11 insertions(+), 22 deletions(-) diff --git a/help.c b/help.c index 888bf8c..e039c14 100644 --- a/help.c +++ b/help.c @@ -3,6 +3,7 @@ #include "exec_cmd.h" #include "levenshtein.h" #include "help.h" +#include "column.h" void add_cmdname(struct cmdnames *cmds, const char *name, int len) { @@ -71,29 +72,17 @@ void exclude_cmds(struct cmdnames *cmds, struct cmdnames *excludes) static void pretty_print_string_list(struct cmdnames *cmds, int longest) { - int cols = 1, rows; - int space = longest + 1; /* min 1 SP between words */ - int max_cols = term_columns() - 1; /* don't print *on* the edge */ - int i, j; - - if (space < max_cols) - cols = max_cols / space; - rows = DIV_ROUND_UP(cmds->cnt, cols); + struct columnizer cp; + int i; - for (i = 0; i < rows; i++) { - printf(" "); + memset(&cp, 0, sizeof(cp)); + cp.flags |= COLUMNIZER_HOMOGENEOUS | COLUMNIZER_COLUMN_FIRST; + cp.space = 1; + cp.left_space = 2; - for (j = 0; j < cols; j++) { - int n = j * rows + i; - int size = space; - if (n >= cmds->cnt) - break; - if (j == cols-1 || n + rows >= cmds->cnt) - size = 1; - printf("%-*s", size, cmds->names[n]->name); - } - putchar('\n'); - } + for (i = 0; i < cmds->cnt; i++) + feed_columnizer(&cp, cmds->names[i]->name); + feed_columnizer(&cp, NULL); } static int is_executable(const char *name) -- 1.7.0.1.370.gd3c5 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html