Magellan Linux

Diff of /trunk/mkinitrd-magellan/busybox/console-tools/resize.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 532 by niro, Sat Sep 1 22:45:15 2007 UTC revision 816 by niro, Fri Apr 24 18:33:46 2009 UTC
# Line 2  Line 2 
2  /*  /*
3   * resize - set terminal width and height.   * resize - set terminal width and height.
4   *   *
5   * Copyright 2006 Bernhard Fischer   * Copyright 2006 Bernhard Reutner-Fischer
6   *   *
7   * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.   * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
8   */   */
9  /* no options, no getopt */  /* no options, no getopt */
10  #include "busybox.h"  #include "libbb.h"
11    
12  int resize_main(int argc, char **argv)  #define ESC "\033"
13    
14    #define old_termios (*(struct termios*)&bb_common_bufsiz1)
15    
16    static void
17    onintr(int sig UNUSED_PARAM)
18    {
19     tcsetattr(STDERR_FILENO, TCSANOW, &old_termios);
20     exit(EXIT_FAILURE);
21    }
22    
23    int resize_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
24    int resize_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
25  {  {
26   struct termios old, new;   struct termios new;
27   struct winsize w = {0,0,0,0};   struct winsize w = { 0, 0, 0, 0 };
28   int ret;   int ret;
29    
30   tcgetattr(STDOUT_FILENO, &old); /* fiddle echo */   /* We use _stderr_ in order to make resize usable
31   new = old;   * 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?
34     */
35    
36     tcgetattr(STDERR_FILENO, &old_termios); /* fiddle echo */
37     new = old_termios;
38   new.c_cflag |= (CLOCAL | CREAD);   new.c_cflag |= (CLOCAL | CREAD);
39   new.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);   new.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
40   tcsetattr(STDOUT_FILENO, TCSANOW, &new);   bb_signals(0
41     + (1 << SIGINT)
42     + (1 << SIGQUIT)
43     + (1 << SIGTERM)
44     + (1 << SIGALRM)
45     , onintr);
46     tcsetattr(STDERR_FILENO, TCSANOW, &new);
47    
48   /* save_cursor_pos 7   /* save_cursor_pos 7
49   * scroll_whole_screen [r   * scroll_whole_screen [r
50   * put_cursor_waaaay_off [$x;$yH   * put_cursor_waaaay_off [$x;$yH
51   * get_cursor_pos [6n   * get_cursor_pos [6n
52   * restore_cursor_pos 8   * restore_cursor_pos 8
53   */   */
54   printf("\0337\033[r\033[999;999H\033[6n");   fprintf(stderr, ESC"7" ESC"[r" ESC"[999;999H" ESC"[6n");
55   scanf("\033[%hu;%huR", &w.ws_row, &w.ws_col);   alarm(3); /* Just in case terminal won't answer */
56   ret = ioctl(STDOUT_FILENO, TIOCSWINSZ, &w);   scanf(ESC"[%hu;%huR", &w.ws_row, &w.ws_col);
57   printf("\0338");   fprintf(stderr, ESC"8");
58   tcsetattr(STDOUT_FILENO, TCSANOW, &old);  
59     /* BTW, other versions of resize recalculate w.ws_xpixel, ws.ws_ypixel
60     * by calculating character cell HxW from old values
61     * (gotten via TIOCGWINSZ) and recomputing *pixel values */
62     ret = ioctl(STDERR_FILENO, TIOCSWINSZ, &w);
63    
64     tcsetattr(STDERR_FILENO, TCSANOW, &old_termios);
65    
66   if (ENABLE_FEATURE_RESIZE_PRINT)   if (ENABLE_FEATURE_RESIZE_PRINT)
67   printf("COLUMNS=%d;LINES=%d;export COLUMNS LINES;\n",   printf("COLUMNS=%d;LINES=%d;export COLUMNS LINES;\n",
68   w.ws_col, w.ws_row);   w.ws_col, w.ws_row);
69    
70   return ret;   return ret;
71  }  }

Legend:
Removed from v.532  
changed lines
  Added in v.816