1 /* vi: set sw=4 ts=4: */
3 * resize - set terminal width and height.
5 * Copyright 2006 Bernhard Fischer
7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
9 /* no options, no getopt */
14 #define old_termios (*(struct termios*)&bb_common_bufsiz1)
17 onintr(int sig ATTRIBUTE_UNUSED)
19 tcsetattr(STDERR_FILENO, TCSANOW, &old_termios);
23 int resize_main(int argc, char **argv);
24 int resize_main(int argc, char **argv)
27 struct winsize w = { 0,0,0,0 };
30 /* We use _stderr_ in order to make resize usable
31 * in shell backticks (those redirect stdout away from tty).
32 * NB: other versions of resize open "/dev/tty"
33 * and operate on it - should we do the same?
36 tcgetattr(STDERR_FILENO, &old_termios); /* fiddle echo */
38 new.c_cflag |= (CLOCAL | CREAD);
39 new.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
40 signal(SIGINT, onintr);
41 signal(SIGQUIT, onintr);
42 signal(SIGTERM, onintr);
43 signal(SIGALRM, onintr);
44 tcsetattr(STDERR_FILENO, TCSANOW, &new);
47 * scroll_whole_screen [r
48 * put_cursor_waaaay_off [$x;$yH
50 * restore_cursor_pos 8
52 fprintf(stderr, ESC"7" ESC"[r" ESC"[999;999H" ESC"[6n");
53 alarm(3); /* Just in case terminal won't answer */
54 scanf(ESC"[%hu;%huR", &w.ws_row, &w.ws_col);
55 fprintf(stderr, ESC"8");
57 /* BTW, other versions of resize recalculate w.ws_xpixel, ws.ws_ypixel
58 * by calculating character cell HxW from old values
59 * (gotten via TIOCGWINSZ) and recomputing *pixel values */
60 ret = ioctl(STDERR_FILENO, TIOCSWINSZ, &w);
62 tcsetattr(STDERR_FILENO, TCSANOW, &old_termios);
64 if (ENABLE_FEATURE_RESIZE_PRINT)
65 printf("COLUMNS=%d;LINES=%d;export COLUMNS LINES;\n",