diff options
Diffstat (limited to 'tools/perf/util/help.c')
-rw-r--r-- | tools/perf/util/help.c | 30 |
1 files changed, 6 insertions, 24 deletions
diff --git a/tools/perf/util/help.c b/tools/perf/util/help.c index fbb00978b2e2..6f2975a00358 100644 --- a/tools/perf/util/help.c +++ b/tools/perf/util/help.c | |||
@@ -4,28 +4,6 @@ | |||
4 | #include "levenshtein.h" | 4 | #include "levenshtein.h" |
5 | #include "help.h" | 5 | #include "help.h" |
6 | 6 | ||
7 | /* most GUI terminals set COLUMNS (although some don't export it) */ | ||
8 | static int term_columns(void) | ||
9 | { | ||
10 | char *col_string = getenv("COLUMNS"); | ||
11 | int n_cols; | ||
12 | |||
13 | if (col_string && (n_cols = atoi(col_string)) > 0) | ||
14 | return n_cols; | ||
15 | |||
16 | #ifdef TIOCGWINSZ | ||
17 | { | ||
18 | struct winsize ws; | ||
19 | if (!ioctl(1, TIOCGWINSZ, &ws)) { | ||
20 | if (ws.ws_col) | ||
21 | return ws.ws_col; | ||
22 | } | ||
23 | } | ||
24 | #endif | ||
25 | |||
26 | return 80; | ||
27 | } | ||
28 | |||
29 | void add_cmdname(struct cmdnames *cmds, const char *name, size_t len) | 7 | void add_cmdname(struct cmdnames *cmds, const char *name, size_t len) |
30 | { | 8 | { |
31 | struct cmdname *ent = malloc(sizeof(*ent) + len + 1); | 9 | struct cmdname *ent = malloc(sizeof(*ent) + len + 1); |
@@ -96,9 +74,13 @@ static void pretty_print_string_list(struct cmdnames *cmds, int longest) | |||
96 | { | 74 | { |
97 | int cols = 1, rows; | 75 | int cols = 1, rows; |
98 | int space = longest + 1; /* min 1 SP between words */ | 76 | int space = longest + 1; /* min 1 SP between words */ |
99 | int max_cols = term_columns() - 1; /* don't print *on* the edge */ | 77 | struct winsize win; |
78 | int max_cols; | ||
100 | int i, j; | 79 | int i, j; |
101 | 80 | ||
81 | get_term_dimensions(&win); | ||
82 | max_cols = win.ws_col - 1; /* don't print *on* the edge */ | ||
83 | |||
102 | if (space < max_cols) | 84 | if (space < max_cols) |
103 | cols = max_cols / space; | 85 | cols = max_cols / space; |
104 | rows = (cmds->cnt + cols - 1) / cols; | 86 | rows = (cmds->cnt + cols - 1) / cols; |
@@ -324,7 +306,7 @@ const char *help_unknown_cmd(const char *cmd) | |||
324 | 306 | ||
325 | main_cmds.names[0] = NULL; | 307 | main_cmds.names[0] = NULL; |
326 | clean_cmdnames(&main_cmds); | 308 | clean_cmdnames(&main_cmds); |
327 | fprintf(stderr, "WARNING: You called a Git program named '%s', " | 309 | fprintf(stderr, "WARNING: You called a perf program named '%s', " |
328 | "which does not exist.\n" | 310 | "which does not exist.\n" |
329 | "Continuing under the assumption that you meant '%s'\n", | 311 | "Continuing under the assumption that you meant '%s'\n", |
330 | cmd, assumed); | 312 | cmd, assumed); |