diff options
author | Junio C Hamano <junkio@cox.net> | 2005-12-21 08:01:00 (GMT) |
---|---|---|
committer | Junio C Hamano <junkio@cox.net> | 2005-12-21 08:01:00 (GMT) |
commit | c2f3bf071ee90b01f2d629921bb04c4f798f02fa (patch) | |
tree | 08ffe5b40e062d596deee47f3869278f4661a858 /git.c | |
parent | 1ed91937e5cd59fdbdfa5f15f6fac132d2b21ce0 (diff) | |
parent | 41f93a2c903a45167b26c2dc93d45ffa9a9bbd49 (diff) | |
download | git-c2f3bf071ee90b01f2d629921bb04c4f798f02fa.zip git-c2f3bf071ee90b01f2d629921bb04c4f798f02fa.tar.gz git-c2f3bf071ee90b01f2d629921bb04c4f798f02fa.tar.bz2 |
GIT 1.0.0v1.0.0
Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'git.c')
-rw-r--r-- | git.c | 32 |
1 files changed, 23 insertions, 9 deletions
@@ -8,6 +8,7 @@ #include <errno.h> #include <limits.h> #include <stdarg.h> +#include <sys/ioctl.h> #include "git-compat-util.h" #ifndef PATH_MAX @@ -26,6 +27,16 @@ static int term_columns(void) if (col_string && (n_cols = atoi(col_string)) > 0) return n_cols; +#ifdef TIOCGWINSZ + { + struct winsize ws; + if (!ioctl(1, TIOCGWINSZ, &ws)) { + if (ws.ws_col) + return ws.ws_col; + } + } +#endif + return 80; } @@ -74,25 +85,28 @@ static int cmdname_compare(const void *a_, const void *b_) static void pretty_print_string_list(struct cmdname **cmdname, int longest) { - int cols = 1; + 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; + int i, j; if (space < max_cols) cols = max_cols / space; + rows = (cmdname_cnt + cols - 1) / cols; qsort(cmdname, cmdname_cnt, sizeof(*cmdname), cmdname_compare); - for (i = 0; i < cmdname_cnt; ) { - int c; + for (i = 0; i < rows; i++) { printf(" "); - for (c = cols; c && i < cmdname_cnt; i++) { - printf("%s", cmdname[i]->name); - - if (--c) - mput_char(' ', space - cmdname[i]->len); + for (j = 0; j < cols; j++) { + int n = j * rows + i; + int size = space; + if (n >= cmdname_cnt) + break; + if (j == cols-1 || n + rows >= cmdname_cnt) + size = 1; + printf("%-*s", size, cmdname[n]->name); } putchar('\n'); } |