diff options
author | Ron Yorston <rmy@pobox.com> | 2016-04-26 11:12:42 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2016-04-26 11:12:42 +0100 |
commit | fd476d8629d489245e18ec278d3c846ab1359eec (patch) | |
tree | da17890f38659af2d2fb6b00872fe7b81a2472b9 | |
parent | 9a7f488564610817a7b9d9d44d7db154e444eb7d (diff) | |
download | busybox-w32-fd476d8629d489245e18ec278d3c846ab1359eec.tar.gz busybox-w32-fd476d8629d489245e18ec278d3c846ab1359eec.tar.bz2 busybox-w32-fd476d8629d489245e18ec278d3c846ab1359eec.zip |
libbb/lineedit: scroll to cursor position on any keypress
Also improve erase_till_end_of_screen. Based on suggestions from
GitHub user avih.
-rw-r--r-- | include/mingw.h | 1 | ||||
-rw-r--r-- | libbb/lineedit.c | 8 | ||||
-rw-r--r-- | win32/winansi.c | 22 |
3 files changed, 13 insertions, 18 deletions
diff --git a/include/mingw.h b/include/mingw.h index f30338ba8..5faef41bf 100644 --- a/include/mingw.h +++ b/include/mingw.h | |||
@@ -154,6 +154,7 @@ int mingw_pclose(FILE *fd); | |||
154 | * ANSI emulation wrappers | 154 | * ANSI emulation wrappers |
155 | */ | 155 | */ |
156 | 156 | ||
157 | void move_cursor_row(int n); | ||
157 | int winansi_putchar(int c); | 158 | int winansi_putchar(int c); |
158 | int winansi_puts(const char *s); | 159 | int winansi_puts(const char *s); |
159 | size_t winansi_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream); | 160 | size_t winansi_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream); |
diff --git a/libbb/lineedit.c b/libbb/lineedit.c index 37c106bd8..e7b9ddfa1 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c | |||
@@ -2440,6 +2440,11 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman | |||
2440 | 2440 | ||
2441 | fflush_all(); | 2441 | fflush_all(); |
2442 | ic = ic_raw = lineedit_read_key(read_key_buffer, timeout); | 2442 | ic = ic_raw = lineedit_read_key(read_key_buffer, timeout); |
2443 | #if ENABLE_PLATFORM_MINGW32 | ||
2444 | /* scroll to cursor position on any keypress */ | ||
2445 | if (isatty(fileno(stdin)) && isatty(fileno(stdout))) | ||
2446 | move_cursor_row(0); | ||
2447 | #endif | ||
2443 | 2448 | ||
2444 | #if ENABLE_FEATURE_REVERSE_SEARCH | 2449 | #if ENABLE_FEATURE_REVERSE_SEARCH |
2445 | again: | 2450 | again: |
@@ -2510,9 +2515,6 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman | |||
2510 | case CTRL('L'): | 2515 | case CTRL('L'): |
2511 | vi_case(CTRL('L')|VI_CMDMODE_BIT:) | 2516 | vi_case(CTRL('L')|VI_CMDMODE_BIT:) |
2512 | /* Control-l -- clear screen */ | 2517 | /* Control-l -- clear screen */ |
2513 | #if ENABLE_PLATFORM_MINGW32 | ||
2514 | printf(ESC"[0A"); /* move to current cursor postion */ | ||
2515 | #endif | ||
2516 | printf(ESC"[H"); /* cursor to top,left */ | 2518 | printf(ESC"[H"); /* cursor to top,left */ |
2517 | redraw(0, command_len - cursor); | 2519 | redraw(0, command_len - cursor); |
2518 | break; | 2520 | break; |
diff --git a/win32/winansi.c b/win32/winansi.c index 78d5d5f5c..ebe831593 100644 --- a/win32/winansi.c +++ b/win32/winansi.c | |||
@@ -109,31 +109,23 @@ static void erase_in_line(void) | |||
109 | static void erase_till_end_of_screen(void) | 109 | static void erase_till_end_of_screen(void) |
110 | { | 110 | { |
111 | CONSOLE_SCREEN_BUFFER_INFO sbi; | 111 | CONSOLE_SCREEN_BUFFER_INFO sbi; |
112 | COORD pos; | 112 | DWORD dummy, len; |
113 | DWORD dummy; | ||
114 | 113 | ||
115 | if (!console) | 114 | if (!console) |
116 | return; | 115 | return; |
117 | 116 | ||
118 | GetConsoleScreenBufferInfo(console, &sbi); | 117 | GetConsoleScreenBufferInfo(console, &sbi); |
119 | FillConsoleOutputCharacterA(console, ' ', | 118 | len = sbi.dwSize.X - sbi.dwCursorPosition.X + |
120 | sbi.dwSize.X - sbi.dwCursorPosition.X, sbi.dwCursorPosition, | 119 | sbi.dwSize.X * (sbi.srWindow.Bottom - sbi.dwCursorPosition.Y); |
120 | |||
121 | FillConsoleOutputCharacterA(console, ' ', len, sbi.dwCursorPosition, | ||
121 | &dummy); | 122 | &dummy); |
122 | FillConsoleOutputAttribute(console, plain_attr, | 123 | FillConsoleOutputAttribute(console, plain_attr, len, sbi.dwCursorPosition, |
123 | sbi.dwSize.X - sbi.dwCursorPosition.X, sbi.dwCursorPosition, | ||
124 | &dummy); | 124 | &dummy); |
125 | 125 | ||
126 | pos.X = 0; | ||
127 | for (pos.Y = sbi.dwCursorPosition.Y+1; pos.Y <= sbi.srWindow.Bottom; | ||
128 | pos.Y++) { | ||
129 | FillConsoleOutputCharacterA(console, ' ', sbi.dwSize.X, | ||
130 | pos, &dummy); | ||
131 | FillConsoleOutputAttribute(console, plain_attr, sbi.dwSize.X, | ||
132 | pos, &dummy); | ||
133 | } | ||
134 | } | 126 | } |
135 | 127 | ||
136 | static void move_cursor_row(int n) | 128 | void move_cursor_row(int n) |
137 | { | 129 | { |
138 | CONSOLE_SCREEN_BUFFER_INFO sbi; | 130 | CONSOLE_SCREEN_BUFFER_INFO sbi; |
139 | 131 | ||