libbb: factor out code which queries screen width

function                                             old     new   delta
get_terminal_width                                     -      17     +17
stty_main                                           1196    1197      +1
pstree_main                                          321     319      -2
ls_main                                              735     731      -4
watch_main                                           232     225      -7
bb_progress_update                                   714     706      -8
ps_main                                              555     543     -12
run_applet_and_exit                                  708     695     -13
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/6 up/down: 18/-46)            Total: -28 byte

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko
2015-10-23 01:44:22 +02:00
parent a960748748
commit 641caaec3d
9 changed files with 15 additions and 15 deletions

View File

@@ -622,7 +622,7 @@ int ps_main(int argc UNUSED_PARAM, char **argv)
* and such large widths */
terminal_width = MAX_WIDTH;
if (isatty(1)) {
get_terminal_width_height(0, &terminal_width, NULL);
terminal_width = get_terminal_width(0);
if (--terminal_width > MAX_WIDTH)
terminal_width = MAX_WIDTH;
}
@@ -672,7 +672,7 @@ int ps_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
if (w_count) {
terminal_width = (w_count == 1) ? 132 : MAX_WIDTH;
} else {
get_terminal_width_height(0, &terminal_width, NULL);
terminal_width = get_terminal_width(0);
/* Go one less... */
if (--terminal_width > MAX_WIDTH)
terminal_width = MAX_WIDTH;

View File

@@ -381,7 +381,7 @@ int pstree_main(int argc UNUSED_PARAM, char **argv)
INIT_G();
get_terminal_width_height(0, &G.output_width, NULL);
G.output_width = get_terminal_width(0);
opt_complementary = "?1";
getopt32(argv, "p");

View File

@@ -72,7 +72,7 @@ int watch_main(int argc UNUSED_PARAM, char **argv)
// STDERR_FILENO is procps3 compat:
// "watch ls 2>/dev/null" does not detect tty size
get_terminal_width_height(STDERR_FILENO, &new_width, NULL);
new_width = get_terminal_width(STDERR_FILENO);
if (new_width != width) {
width = new_width;
free(header);