diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2010-04-18 22:09:30 -0700 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-04-18 22:09:30 -0700 |
commit | c175c4664734e5a363d8cc8668c08f551eff1485 (patch) | |
tree | 7a71009d3d5a9b3a0e8be65bf020f4605cee4bae /libbb | |
parent | def4783a8a8b00f58d224ff6735d3532809aeb54 (diff) | |
download | busybox-w32-c175c4664734e5a363d8cc8668c08f551eff1485.tar.gz busybox-w32-c175c4664734e5a363d8cc8668c08f551eff1485.tar.bz2 busybox-w32-c175c4664734e5a363d8cc8668c08f551eff1485.zip |
vi: discover window size even on serial consoles. optional
function old new delta
edit_file 671 761 +90
wh_helper - 57 +57
query_screen_dimensions 54 63 +9
ar_main 533 542 +9
refresh 767 773 +6
vi_main 242 243 +1
text_yank 56 54 -2
get_terminal_width_height 180 135 -45
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 5/2 up/down: 172/-47) Total: 125 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/read_key.c | 2 | ||||
-rw-r--r-- | libbb/xfuncs.c | 54 |
2 files changed, 31 insertions, 25 deletions
diff --git a/libbb/read_key.c b/libbb/read_key.c index 8422976c9..64557ab14 100644 --- a/libbb/read_key.c +++ b/libbb/read_key.c | |||
@@ -214,7 +214,7 @@ int64_t FAST_FUNC read_key(int fd, char *buffer, int timeout) | |||
214 | } | 214 | } |
215 | n++; | 215 | n++; |
216 | /* Try to decipher "ESC [ NNN ; NNN R" sequence */ | 216 | /* Try to decipher "ESC [ NNN ; NNN R" sequence */ |
217 | if (ENABLE_FEATURE_EDITING_ASK_TERMINAL | 217 | if ((ENABLE_FEATURE_EDITING_ASK_TERMINAL || ENABLE_FEATURE_VI_ASK_TERMINAL) |
218 | && n >= 5 | 218 | && n >= 5 |
219 | && buffer[0] == '[' | 219 | && buffer[0] == '[' |
220 | && buffer[n-1] == 'R' | 220 | && buffer[n-1] == 'R' |
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c index aec165f06..d93dd2af9 100644 --- a/libbb/xfuncs.c +++ b/libbb/xfuncs.c | |||
@@ -210,34 +210,40 @@ char* FAST_FUNC xmalloc_ttyname(int fd) | |||
210 | return buf; | 210 | return buf; |
211 | } | 211 | } |
212 | 212 | ||
213 | /* It is perfectly ok to pass in a NULL for either width or for | 213 | static int wh_helper(int value, int def_val, const char *env_name, int *err) |
214 | * height, in which case that value will not be set. */ | ||
215 | int FAST_FUNC get_terminal_width_height(int fd, unsigned *width, unsigned *height) | ||
216 | { | 214 | { |
217 | struct winsize win = { 0, 0, 0, 0 }; | 215 | if (value == 0) { |
218 | int ret = ioctl(fd, TIOCGWINSZ, &win); | 216 | char *s = getenv(env_name); |
219 | 217 | if (s) { | |
220 | if (height) { | 218 | value = atoi(s); |
221 | if (!win.ws_row) { | 219 | /* If LINES/COLUMNS are set, pretent that there is |
222 | char *s = getenv("LINES"); | 220 | * no error getting w/h, this prevents some ugly |
223 | if (s) win.ws_row = atoi(s); | 221 | * cursor tricks by our callers */ |
224 | } | 222 | *err = 0; |
225 | if (win.ws_row <= 1 || win.ws_row >= 30000) | ||
226 | win.ws_row = 24; | ||
227 | *height = (int) win.ws_row; | ||
228 | } | ||
229 | |||
230 | if (width) { | ||
231 | if (!win.ws_col) { | ||
232 | char *s = getenv("COLUMNS"); | ||
233 | if (s) win.ws_col = atoi(s); | ||
234 | } | 223 | } |
235 | if (win.ws_col <= 1 || win.ws_col >= 30000) | ||
236 | win.ws_col = 80; | ||
237 | *width = (int) win.ws_col; | ||
238 | } | 224 | } |
225 | if (value <= 1 || value >= 30000) | ||
226 | value = def_val; | ||
227 | return value; | ||
228 | } | ||
239 | 229 | ||
240 | return ret; | 230 | /* It is perfectly ok to pass in a NULL for either width or for |
231 | * height, in which case that value will not be set. */ | ||
232 | int FAST_FUNC get_terminal_width_height(int fd, unsigned *width, unsigned *height) | ||
233 | { | ||
234 | struct winsize win; | ||
235 | int err; | ||
236 | |||
237 | win.ws_row = 0; | ||
238 | win.ws_col = 0; | ||
239 | /* I've seen ioctl returning 0, but row/col is (still?) 0. | ||
240 | * We treat that as an error too. */ | ||
241 | err = ioctl(fd, TIOCGWINSZ, &win) != 0 || win.ws_row == 0; | ||
242 | if (height) | ||
243 | *height = wh_helper(win.ws_row, 24, "LINES", &err); | ||
244 | if (width) | ||
245 | *width = wh_helper(win.ws_col, 80, "COLUMNS", &err); | ||
246 | return err; | ||
241 | } | 247 | } |
242 | 248 | ||
243 | int FAST_FUNC tcsetattr_stdin_TCSANOW(const struct termios *tp) | 249 | int FAST_FUNC tcsetattr_stdin_TCSANOW(const struct termios *tp) |