diff options
Diffstat (limited to 'editors/vi.c')
-rw-r--r-- | editors/vi.c | 41 |
1 files changed, 31 insertions, 10 deletions
diff --git a/editors/vi.c b/editors/vi.c index 28612508f..d9124fd76 100644 --- a/editors/vi.c +++ b/editors/vi.c | |||
@@ -60,18 +60,18 @@ enum { | |||
60 | 60 | ||
61 | /* vt102 typical ESC sequence */ | 61 | /* vt102 typical ESC sequence */ |
62 | /* terminal standout start/normal ESC sequence */ | 62 | /* terminal standout start/normal ESC sequence */ |
63 | static const char SOs[] ALIGN1 = "\033[7m"; | 63 | #define SOs "\033[7m" |
64 | static const char SOn[] ALIGN1 = "\033[0m"; | 64 | #define SOn "\033[0m" |
65 | /* terminal bell sequence */ | 65 | /* terminal bell sequence */ |
66 | static const char bell[] ALIGN1 = "\007"; | 66 | #define bell "\007" |
67 | /* Clear-end-of-line and Clear-end-of-screen ESC sequence */ | 67 | /* Clear-end-of-line and Clear-end-of-screen ESC sequence */ |
68 | static const char Ceol[] ALIGN1 = "\033[0K"; | 68 | #define Ceol "\033[K" |
69 | static const char Ceos[] ALIGN1 = "\033[0J"; | 69 | #define Ceos "\033[J" |
70 | /* Cursor motion arbitrary destination ESC sequence */ | 70 | /* Cursor motion arbitrary destination ESC sequence */ |
71 | static const char CMrc[] ALIGN1 = "\033[%d;%dH"; | 71 | #define CMrc "\033[%u;%uH" |
72 | /* Cursor motion up and down ESC sequence */ | 72 | /* Cursor motion up and down ESC sequence */ |
73 | static const char CMup[] ALIGN1 = "\033[A"; | 73 | #define CMup "\033[A" |
74 | static const char CMdown[] ALIGN1 = "\n"; | 74 | #define CMdown "\n" |
75 | 75 | ||
76 | #if ENABLE_FEATURE_VI_DOT_CMD || ENABLE_FEATURE_VI_YANKMARK | 76 | #if ENABLE_FEATURE_VI_DOT_CMD || ENABLE_FEATURE_VI_YANKMARK |
77 | // cmds modifying text[] | 77 | // cmds modifying text[] |
@@ -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 | ||
@@ -2306,7 +2327,7 @@ static int file_size(const char *fn) // what is the byte size of "fn" | |||
2306 | int cnt; | 2327 | int cnt; |
2307 | 2328 | ||
2308 | cnt = -1; | 2329 | cnt = -1; |
2309 | if (fn && fn[0] && stat(fn, &st_buf) == 0) // see if file exists | 2330 | if (fn && stat(fn, &st_buf) == 0) // see if file exists |
2310 | cnt = (int) st_buf.st_size; | 2331 | cnt = (int) st_buf.st_size; |
2311 | return cnt; | 2332 | return cnt; |
2312 | } | 2333 | } |