From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 5/7] help: reuse struct column_layout
Date: Tue, 8 Feb 2011 22:22:19 +0700 [thread overview]
Message-ID: <1297178541-31124-6-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1297178541-31124-1-git-send-email-pclouds@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
help.c | 33 +++++++++++----------------------
1 files changed, 11 insertions(+), 22 deletions(-)
diff --git a/help.c b/help.c
index 1344208..dc06f63 100644
--- a/help.c
+++ b/help.c
@@ -4,6 +4,7 @@
#include "levenshtein.h"
#include "help.h"
#include "common-cmds.h"
+#include "column.h"
void add_cmdname(struct cmdnames *cmds, const char *name, int len)
{
@@ -72,29 +73,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 column_layout c;
+ int i;
- for (i = 0; i < rows; i++) {
- printf(" ");
+ memset(&c, 0, sizeof(c));
+ c.mode = COL_COLUMN_FIRST;
+ c.width = term_columns();
- 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(&c.items, cmds->names[i]->name);
+ display_columns(&c, 2, " ");
+ string_list_clear(&c.items, 0);
}
static int is_executable(const char *name)
--
1.7.2.2
next prev parent reply other threads:[~2011-02-08 15:24 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-08 15:22 [PATCH/RFC 0/7] Column output Nguyễn Thái Ngọc Duy
2011-02-08 15:22 ` [PATCH 1/7] Move term_columns() to pager.c and save terminal width before pager Nguyễn Thái Ngọc Duy
2011-02-09 5:14 ` Jonathan Nieder
2011-02-08 15:22 ` [PATCH 2/7] Add column layout Nguyễn Thái Ngọc Duy
2011-02-09 7:36 ` Jonathan Nieder
2011-02-09 11:24 ` Nguyen Thai Ngoc Duy
2011-02-08 15:22 ` [PATCH 3/7] parseopt: OPT_COLUMN to set struct column_layout.mode Nguyễn Thái Ngọc Duy
2011-02-08 15:22 ` [PATCH 4/7] add core.column Nguyễn Thái Ngọc Duy
2011-02-08 15:22 ` Nguyễn Thái Ngọc Duy [this message]
2011-02-09 7:39 ` [PATCH 5/7] help: reuse struct column_layout Jonathan Nieder
2011-02-09 11:21 ` Nguyen Thai Ngoc Duy
2011-02-08 15:22 ` [PATCH 6/7] tag: support column output with --column Nguyễn Thái Ngọc Duy
2011-02-09 21:51 ` Junio C Hamano
2011-02-10 2:35 ` Nguyen Thai Ngoc Duy
2011-02-10 2:54 ` Miles Bader
2011-02-08 15:22 ` [PATCH 7/7] branch: " Nguyễn Thái Ngọc Duy
2011-02-08 22:47 ` [PATCH/RFC 0/7] Column output Jeff King
2011-02-09 0:13 ` Nguyen Thai Ngoc Duy
2011-02-09 5:42 ` Jonathan Nieder
2011-02-09 5:59 ` Nguyen Thai Ngoc Duy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1297178541-31124-6-git-send-email-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).