Commit 33fa11d4b53dcda0f71929a60d60e51ad46e926d
1 parent
31211df1
Implement ^W in readline.c, by Michal Hanselmann.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@3016 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
1 changed file
with
43 additions
and
0 deletions
readline.c
| @@ -156,6 +156,45 @@ static void term_backspace(void) | @@ -156,6 +156,45 @@ static void term_backspace(void) | ||
| 156 | } | 156 | } |
| 157 | } | 157 | } |
| 158 | 158 | ||
| 159 | +static void term_backword(void) | ||
| 160 | +{ | ||
| 161 | + int start; | ||
| 162 | + | ||
| 163 | + if (term_cmd_buf_index == 0 || term_cmd_buf_index > term_cmd_buf_size) { | ||
| 164 | + return; | ||
| 165 | + } | ||
| 166 | + | ||
| 167 | + start = term_cmd_buf_index - 1; | ||
| 168 | + | ||
| 169 | + /* find first word (backwards) */ | ||
| 170 | + while (start > 0) { | ||
| 171 | + if (!isspace(term_cmd_buf[start])) { | ||
| 172 | + break; | ||
| 173 | + } | ||
| 174 | + | ||
| 175 | + --start; | ||
| 176 | + } | ||
| 177 | + | ||
| 178 | + /* find first space (backwards) */ | ||
| 179 | + while (start > 0) { | ||
| 180 | + if (isspace(term_cmd_buf[start])) { | ||
| 181 | + ++start; | ||
| 182 | + break; | ||
| 183 | + } | ||
| 184 | + | ||
| 185 | + --start; | ||
| 186 | + } | ||
| 187 | + | ||
| 188 | + /* remove word */ | ||
| 189 | + if (start < term_cmd_buf_index) { | ||
| 190 | + memmove(term_cmd_buf + start, | ||
| 191 | + term_cmd_buf + term_cmd_buf_index, | ||
| 192 | + term_cmd_buf_size - term_cmd_buf_index); | ||
| 193 | + term_cmd_buf_size -= term_cmd_buf_index - start; | ||
| 194 | + term_cmd_buf_index = start; | ||
| 195 | + } | ||
| 196 | +} | ||
| 197 | + | ||
| 159 | static void term_bol(void) | 198 | static void term_bol(void) |
| 160 | { | 199 | { |
| 161 | term_cmd_buf_index = 0; | 200 | term_cmd_buf_index = 0; |
| @@ -338,6 +377,10 @@ void readline_handle_byte(int ch) | @@ -338,6 +377,10 @@ void readline_handle_byte(int ch) | ||
| 338 | /* NOTE: readline_start can be called here */ | 377 | /* NOTE: readline_start can be called here */ |
| 339 | term_readline_func(term_readline_opaque, term_cmd_buf); | 378 | term_readline_func(term_readline_opaque, term_cmd_buf); |
| 340 | break; | 379 | break; |
| 380 | + case 23: | ||
| 381 | + /* ^W */ | ||
| 382 | + term_backword(); | ||
| 383 | + break; | ||
| 341 | case 27: | 384 | case 27: |
| 342 | term_esc_state = IS_ESC; | 385 | term_esc_state = IS_ESC; |
| 343 | break; | 386 | break; |