Signed-off-by: Nguyán ThÃi Ngác Duy <pclouds@xxxxxxxxx> --- help.c | 30 ++++++++---------------------- 1 files changed, 8 insertions(+), 22 deletions(-) diff --git a/help.c b/help.c index 768f64c..dcc8b81 100644 --- a/help.c +++ b/help.c @@ -4,6 +4,7 @@ #include "levenshtein.h" #include "help.h" #include "common-cmds.h" +#include "string-list.h" #include "column.h" void add_cmdname(struct cmdnames *cmds, const char *name, int len) @@ -73,29 +74,14 @@ 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); - - for (i = 0; i < rows; i++) { - printf(" "); + struct string_list list = STRING_LIST_INIT_NODUP; + int i; - 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++) + string_list_append(&list, cmds->names[i]->name); + display_columns(&list, COL_MODE_COLUMN | COL_ENABLED, + term_columns(), 1, " "); + string_list_clear(&list, 0); } static int is_executable(const char *name) -- 1.7.4.74.g639db -- 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