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 /editors/vi.c | |
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 'editors/vi.c')
-rw-r--r-- | editors/vi.c | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/editors/vi.c b/editors/vi.c index f925984ba..d3a35e781 100644 --- a/editors/vi.c +++ b/editors/vi.c | |||
@@ -138,6 +138,9 @@ struct globals { | |||
138 | int save_argc; // how many file names on cmd line | 138 | int save_argc; // how many file names on cmd line |
139 | int cmdcnt; // repetition count | 139 | int cmdcnt; // repetition count |
140 | unsigned rows, columns; // the terminal screen is this size | 140 | unsigned rows, columns; // the terminal screen is this size |
141 | #if ENABLE_FEATURE_VI_ASK_TERMINAL | ||
142 | int get_rowcol_error; | ||
143 | #endif | ||
141 | int crow, ccol; // cursor is on Crow x Ccol | 144 | int crow, ccol; // cursor is on Crow x Ccol |
142 | int offset; // chars scrolled off the screen to the left | 145 | int offset; // chars scrolled off the screen to the left |
143 | int have_status_msg; // is default edit status needed? | 146 | int have_status_msg; // is default edit status needed? |
@@ -503,7 +506,11 @@ static int init_text_buffer(char *fn) | |||
503 | #if ENABLE_FEATURE_VI_WIN_RESIZE | 506 | #if ENABLE_FEATURE_VI_WIN_RESIZE |
504 | static void query_screen_dimensions(void) | 507 | static void query_screen_dimensions(void) |
505 | { | 508 | { |
506 | get_terminal_width_height(STDIN_FILENO, &columns, &rows); | 509 | # if ENABLE_FEATURE_VI_ASK_TERMINAL |
510 | if (!G.get_rowcol_error) | ||
511 | G.get_rowcol_error = | ||
512 | # endif | ||
513 | get_terminal_width_height(STDIN_FILENO, &columns, &rows); | ||
507 | if (rows > MAX_SCR_ROWS) | 514 | if (rows > MAX_SCR_ROWS) |
508 | rows = MAX_SCR_ROWS; | 515 | rows = MAX_SCR_ROWS; |
509 | if (columns > MAX_SCR_COLS) | 516 | if (columns > MAX_SCR_COLS) |
@@ -530,6 +537,20 @@ static void edit_file(char *fn) | |||
530 | columns = 80; | 537 | columns = 80; |
531 | size = 0; | 538 | size = 0; |
532 | query_screen_dimensions(); | 539 | query_screen_dimensions(); |
540 | #if ENABLE_FEATURE_VI_ASK_TERMINAL | ||
541 | if (G.get_rowcol_error /* TODO? && no input on stdin */) { | ||
542 | uint64_t k; | ||
543 | write1("\033[999;999H" "\033[6n"); | ||
544 | fflush_all(); | ||
545 | k = read_key(STDIN_FILENO, readbuffer, /*timeout_ms:*/ 100); | ||
546 | if ((int32_t)k == KEYCODE_CURSOR_POS) { | ||
547 | uint32_t rc = (k >> 32); | ||
548 | columns = (rc & 0x7fff); | ||
549 | rows = ((rc >> 16) & 0x7fff); | ||
550 | } | ||
551 | query_screen_dimensions(); | ||
552 | } | ||
553 | #endif | ||
533 | new_screen(rows, columns); // get memory for virtual screen | 554 | new_screen(rows, columns); // get memory for virtual screen |
534 | init_text_buffer(fn); | 555 | init_text_buffer(fn); |
535 | 556 | ||