git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 7/9] help: reuse display_columns() for help -a

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Mar 20, 2011, 12:57 UTC
Message-ID
<1300625873-18435-8-git-send-email-pclouds@gmail.com>
In-Reply-To
<1300625873-18435-1-git-send-email-pclouds@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 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
Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 8 of 13 in “column output v3”
  1. 0/9 column output v3Nguyễn Thái Ngọc Duy, Mar 20, 2011
  2. 1/9 Move term_columns() to pager.c and save terminal width before pagerNguyễn Thái Ngọc Duy, Mar 20, 2011
  3. 2/9 Add display_columns() to display in columnar layoutNguyễn Thái Ngọc Duy, Mar 20, 2011
  4. 3/9 column: add functions to parse column settingsNguyễn Thái Ngọc Duy, Mar 20, 2011
  5. 4/9 display_columns: add COL_MODE_{COLUMN,ROW} modeNguyễn Thái Ngọc Duy, Mar 20, 2011
  6. 5/9 display_columns: add COL_DENSE to do unequal column layoutNguyễn Thái Ngọc Duy, Mar 20, 2011
  7. 6/9 column: add column.ui for default column output settingsNguyễn Thái Ngọc Duy, Mar 20, 2011
  8. 7/9 help: reuse display_columns() for help -aNguyễn Thái Ngọc Duy, Mar 20, 2011
  9. 7/9 help: reuse display_columns() for help -aNguyễn Thái Ngọc Duy, Mar 20, 2011
  10. 8/9 tag: add --columnNguyễn Thái Ngọc Duy, Mar 20, 2011
  11. 9/9 branch: add --columnNguyễn Thái Ngọc Duy, Mar 20, 2011
  12. Teemu LikonenMar 20, 2011
  13. 9/9 branch: add --columnNguyễn Thái Ngọc Duy, Mar 20, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.