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

[PATCH 08/16] help: reuse display_columns() for help -a

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Feb 9, 2011, 12:24 UTC
Message-ID
<1297254284-3729-9-git-send-email-pclouds@gmail.com>
In-Reply-To
<1297254284-3729-1-git-send-email-pclouds@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 help.c |   29 +++++++----------------------
 1 files changed, 7 insertions(+), 22 deletions(-)
diff --git a/help.c b/help.c
index 768f64c..81942f9 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,13 @@ 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, term_columns(), 1, "  ");
+	string_list_clear(&list, 0);
 }
 
 static int is_executable(const char *name)
-- 
1.7.2.2
Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 9 of 17 in “column output (v2) and git-ls”
  1. 00/16 column output (v2) and git-lsNguyễn Thái Ngọc Duy, Feb 9, 2011
  2. 01/16 Move term_columns() to pager.c and save terminal width before pagerNguyễn Thái Ngọc Duy, Feb 9, 2011
  3. 02/16 Add display_columns() to display in column layoutNguyễn Thái Ngọc Duy, Feb 9, 2011
  4. 03/16 display_columns: add COL_MODE_{COLUMN,ROW} modeNguyễn Thái Ngọc Duy, Feb 9, 2011
  5. 04/16 display_columns: add COL_DENSE to do unequal column layoutNguyễn Thái Ngọc Duy, Feb 9, 2011
  6. 05/16 Add test-column for testing column layoutNguyễn Thái Ngọc Duy, Feb 9, 2011
  7. 06/16 Add core.columnNguyễn Thái Ngọc Duy, Feb 9, 2011
  8. 07/16 parseopt: OPT_COLUMN to set struct column_layout.modeNguyễn Thái Ngọc Duy, Feb 9, 2011
  9. 08/16 help: reuse display_columns() for help -aNguyễn Thái Ngọc Duy, Feb 9, 2011
  10. 09/16 tag: add --columnNguyễn Thái Ngọc Duy, Feb 9, 2011
  11. 10/16 branch: add --columnNguyễn Thái Ngọc Duy, Feb 9, 2011
  12. 11/16 Add ls commandNguyễn Thái Ngọc Duy, Feb 9, 2011
  13. 12/16 ls: add --columnNguyễn Thái Ngọc Duy, Feb 9, 2011
  14. 13/16 ls: add --recursive and turn default to non-recursive modeNguyễn Thái Ngọc Duy, Feb 9, 2011
  15. 14/16 ls: immitate UNIX ls output styleNguyễn Thái Ngọc Duy, Feb 9, 2011
  16. 15/16 ls: strip common directory prefix from outputNguyễn Thái Ngọc Duy, Feb 9, 2011
  17. 16/16 ls: color outputNguyễn Thái Ngọc Duy, Feb 9, 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.