diff options
author | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2007-03-10 16:32:14 +0000 |
---|---|---|
committer | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2007-03-10 16:32:14 +0000 |
commit | ee5eb106c8ab883ff5452a894d3f52b229a469af (patch) | |
tree | 8cb052205ab9f9e97233afe39ddb2c6253ab8d1a | |
parent | 3cbe0f2d98a93afc09e148d8fa641e1cbaee3a9c (diff) | |
download | busybox-w32-ee5eb106c8ab883ff5452a894d3f52b229a469af.tar.gz busybox-w32-ee5eb106c8ab883ff5452a894d3f52b229a469af.tar.bz2 busybox-w32-ee5eb106c8ab883ff5452a894d3f52b229a469af.zip |
more: do not mess with "/dev/console" (!);
fill whole 1st screen (was "screen sans one line");
fall back to cat if redirected or no ctty
less: fall back to cat if no ctty (was exiting)
resize: cosmetics
git-svn-id: svn://busybox.net/trunk/busybox@18061 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r-- | console-tools/resize.c | 8 | ||||
-rw-r--r-- | miscutils/less.c | 5 | ||||
-rw-r--r-- | util-linux/more.c | 77 |
3 files changed, 43 insertions, 47 deletions
diff --git a/console-tools/resize.c b/console-tools/resize.c index 2fe5526fb..40a1b4ee0 100644 --- a/console-tools/resize.c +++ b/console-tools/resize.c | |||
@@ -9,6 +9,8 @@ | |||
9 | /* no options, no getopt */ | 9 | /* no options, no getopt */ |
10 | #include "busybox.h" | 10 | #include "busybox.h" |
11 | 11 | ||
12 | #define ESC "\033" | ||
13 | |||
12 | int resize_main(int argc, char **argv); | 14 | int resize_main(int argc, char **argv); |
13 | int resize_main(int argc, char **argv) | 15 | int resize_main(int argc, char **argv) |
14 | { | 16 | { |
@@ -27,10 +29,10 @@ int resize_main(int argc, char **argv) | |||
27 | * get_cursor_pos [6n | 29 | * get_cursor_pos [6n |
28 | * restore_cursor_pos 8 | 30 | * restore_cursor_pos 8 |
29 | */ | 31 | */ |
30 | printf("\0337\033[r\033[999;999H\033[6n"); | 32 | printf(ESC"7" ESC"[r" ESC"[999;999H" ESC"[6n"); |
31 | scanf("\033[%hu;%huR", &w.ws_row, &w.ws_col); | 33 | scanf(ESC"[%hu;%huR", &w.ws_row, &w.ws_col); |
32 | ret = ioctl(STDOUT_FILENO, TIOCSWINSZ, &w); | 34 | ret = ioctl(STDOUT_FILENO, TIOCSWINSZ, &w); |
33 | printf("\0338"); | 35 | printf(ESC"8"); |
34 | tcsetattr(STDOUT_FILENO, TCSANOW, &old); | 36 | tcsetattr(STDOUT_FILENO, TCSANOW, &old); |
35 | if (ENABLE_FEATURE_RESIZE_PRINT) | 37 | if (ENABLE_FEATURE_RESIZE_PRINT) |
36 | printf("COLUMNS=%d;LINES=%d;export COLUMNS LINES;\n", | 38 | printf("COLUMNS=%d;LINES=%d;export COLUMNS LINES;\n", |
diff --git a/miscutils/less.c b/miscutils/less.c index 79732cc41..a7041552d 100644 --- a/miscutils/less.c +++ b/miscutils/less.c | |||
@@ -1251,6 +1251,9 @@ int less_main(int argc, char **argv) | |||
1251 | * is not a tty and turns into cat. This makes sense. */ | 1251 | * is not a tty and turns into cat. This makes sense. */ |
1252 | if (!isatty(STDOUT_FILENO)) | 1252 | if (!isatty(STDOUT_FILENO)) |
1253 | return bb_cat(argv); | 1253 | return bb_cat(argv); |
1254 | kbd_fd = open(CURRENT_TTY, O_RDONLY); | ||
1255 | if (kbd_fd < 0) | ||
1256 | return bb_cat(argv); | ||
1254 | 1257 | ||
1255 | if (!num_files) { | 1258 | if (!num_files) { |
1256 | if (isatty(STDIN_FILENO)) { | 1259 | if (isatty(STDIN_FILENO)) { |
@@ -1261,8 +1264,6 @@ int less_main(int argc, char **argv) | |||
1261 | } else | 1264 | } else |
1262 | filename = xstrdup(files[0]); | 1265 | filename = xstrdup(files[0]); |
1263 | 1266 | ||
1264 | kbd_fd = xopen(CURRENT_TTY, O_RDONLY); | ||
1265 | |||
1266 | get_terminal_width_height(kbd_fd, &width, &max_displayed_line); | 1267 | get_terminal_width_height(kbd_fd, &width, &max_displayed_line); |
1267 | /* 20: two tabstops + 4 */ | 1268 | /* 20: two tabstops + 4 */ |
1268 | if (width < 20 || max_displayed_line < 3) | 1269 | if (width < 20 || max_displayed_line < 3) |
diff --git a/util-linux/more.c b/util-linux/more.c index 23ac526fa..2a38ef326 100644 --- a/util-linux/more.c +++ b/util-linux/more.c | |||
@@ -50,52 +50,46 @@ int more_main(int argc, char **argv) | |||
50 | int terminal_width; | 50 | int terminal_width; |
51 | int terminal_height; | 51 | int terminal_height; |
52 | 52 | ||
53 | argc--; | ||
54 | argv++; | 53 | argv++; |
54 | /* Another popular pager, most, detects when stdout | ||
55 | * is not a tty and turns into cat. This makes sense. */ | ||
56 | if (!isatty(STDOUT_FILENO)) | ||
57 | return bb_cat(argv); | ||
58 | cin = fopen(CURRENT_TTY, "r"); | ||
59 | if (!cin) | ||
60 | return bb_cat(argv); | ||
55 | 61 | ||
56 | cin = stdin; | ||
57 | /* use input from terminal unless we do "more >outfile" */ | ||
58 | if (isatty(STDOUT_FILENO)) { | ||
59 | cin = fopen(CURRENT_TTY, "r"); | ||
60 | /* Huh? why not just fail if "/dev/tty" isn't available? | ||
61 | * If user has no ctty, it's his own problem */ | ||
62 | if (!cin) | ||
63 | cin = xfopen(DEV_CONSOLE, "r"); | ||
64 | please_display_more_prompt = 2; | ||
65 | #if ENABLE_FEATURE_USE_TERMIOS | 62 | #if ENABLE_FEATURE_USE_TERMIOS |
66 | cin_fileno = fileno(cin); | 63 | cin_fileno = fileno(cin); |
67 | getTermSettings(cin_fileno, &initial_settings); | 64 | getTermSettings(cin_fileno, &initial_settings); |
68 | new_settings = initial_settings; | 65 | new_settings = initial_settings; |
69 | new_settings.c_lflag &= ~ICANON; | 66 | new_settings.c_lflag &= ~ICANON; |
70 | new_settings.c_lflag &= ~ECHO; | 67 | new_settings.c_lflag &= ~ECHO; |
71 | new_settings.c_cc[VMIN] = 1; | 68 | new_settings.c_cc[VMIN] = 1; |
72 | new_settings.c_cc[VTIME] = 0; | 69 | new_settings.c_cc[VTIME] = 0; |
73 | setTermSettings(cin_fileno, &new_settings); | 70 | setTermSettings(cin_fileno, &new_settings); |
74 | atexit(set_tty_to_initial_mode); | 71 | atexit(set_tty_to_initial_mode); |
75 | signal(SIGINT, gotsig); | 72 | signal(SIGINT, gotsig); |
76 | signal(SIGQUIT, gotsig); | 73 | signal(SIGQUIT, gotsig); |
77 | signal(SIGTERM, gotsig); | 74 | signal(SIGTERM, gotsig); |
78 | #endif | 75 | #endif |
79 | } | 76 | please_display_more_prompt = 2; |
80 | 77 | ||
81 | do { | 78 | do { |
82 | file = stdin; | 79 | file = stdin; |
83 | if (argc != 0) { | 80 | if (*argv) { |
84 | file = fopen_or_warn(*argv, "r"); | 81 | file = fopen_or_warn(*argv, "r"); |
85 | if (!file) | 82 | if (!file) |
86 | goto loop; | 83 | continue; |
87 | } | 84 | } |
88 | |||
89 | st.st_size = 0; | 85 | st.st_size = 0; |
90 | fstat(fileno(file), &st); | 86 | fstat(fileno(file), &st); |
91 | 87 | ||
92 | please_display_more_prompt &= ~1; | 88 | please_display_more_prompt &= ~1; |
93 | 89 | /* never returns w, h <= 1 */ | |
94 | get_terminal_width_height(fileno(cin), &terminal_width, &terminal_height); | 90 | get_terminal_width_height(fileno(cin), &terminal_width, &terminal_height); |
95 | if (terminal_height > 4) | 91 | terminal_width -= 1; |
96 | terminal_height -= 2; | 92 | terminal_height -= 1; |
97 | if (terminal_width > 0) | ||
98 | terminal_width -= 1; | ||
99 | 93 | ||
100 | len = 0; | 94 | len = 0; |
101 | lines = 0; | 95 | lines = 0; |
@@ -104,7 +98,7 @@ int more_main(int argc, char **argv) | |||
104 | 98 | ||
105 | if ((please_display_more_prompt & 3) == 3) { | 99 | if ((please_display_more_prompt & 3) == 3) { |
106 | len = printf("--More-- "); | 100 | len = printf("--More-- "); |
107 | if (file != stdin && st.st_size > 0) { | 101 | if (/*file != stdin &&*/ st.st_size > 0) { |
108 | len += printf("(%d%% of %"OFF_FMT"d bytes)", | 102 | len += printf("(%d%% of %"OFF_FMT"d bytes)", |
109 | (int) (ftello(file)*100 / st.st_size), | 103 | (int) (ftello(file)*100 / st.st_size), |
110 | st.st_size); | 104 | st.st_size); |
@@ -123,7 +117,9 @@ int more_main(int argc, char **argv) | |||
123 | printf("\r%*s\r", len, ""); | 117 | printf("\r%*s\r", len, ""); |
124 | len = 0; | 118 | len = 0; |
125 | lines = 0; | 119 | lines = 0; |
126 | page_height = terminal_height; | 120 | /* Bottom line on page will become top line |
121 | * after one page forward. Thus -1: */ | ||
122 | page_height = terminal_height - 1; | ||
127 | please_display_more_prompt &= ~1; | 123 | please_display_more_prompt &= ~1; |
128 | 124 | ||
129 | if (input == 'q') | 125 | if (input == 'q') |
@@ -151,12 +147,9 @@ int more_main(int argc, char **argv) | |||
151 | int quot, rem; | 147 | int quot, rem; |
152 | quot = len / terminal_width; | 148 | quot = len / terminal_width; |
153 | rem = len - (quot * terminal_width); | 149 | rem = len - (quot * terminal_width); |
154 | if (quot) { | 150 | page_height -= (quot - 1); |
155 | if (rem) | 151 | if (rem) |
156 | page_height -= quot; | 152 | page_height--; |
157 | else | ||
158 | page_height -= (quot - 1); | ||
159 | } | ||
160 | } | 153 | } |
161 | if (++lines >= page_height) { | 154 | if (++lines >= page_height) { |
162 | please_display_more_prompt |= 1; | 155 | please_display_more_prompt |= 1; |
@@ -168,13 +161,13 @@ int more_main(int argc, char **argv) | |||
168 | * key other than a return is hit, scroll by one page | 161 | * key other than a return is hit, scroll by one page |
169 | */ | 162 | */ |
170 | putc(c, stdout); | 163 | putc(c, stdout); |
164 | /* My small mind cannot fathom tabs, backspaces, | ||
165 | * and UTF-8 */ | ||
171 | len++; | 166 | len++; |
172 | } | 167 | } |
173 | fclose(file); | 168 | fclose(file); |
174 | fflush(stdout); | 169 | fflush(stdout); |
175 | loop: | 170 | } while (*argv && *++argv); |
176 | argv++; | ||
177 | } while (--argc > 0); | ||
178 | end: | 171 | end: |
179 | return 0; | 172 | return 0; |
180 | } | 173 | } |