2014-11-08 10:58:05 (UTC-02:00)
Marcel Rodrigues <marcelgmr@gmail.com>
Better line editing.
diff --git a/rover.c b/rover.c index 7ae8a27..307f1cb 100644 --- a/rover.c +++ b/rover.c @@ -348,22 +348,21 @@ main() } else if (!strcmp(key, RVK_SEARCH)) { if (!rover.nfiles) continue; - int ch, length, sel, oldsel, oldscroll; + int length, sel, oldsel, oldscroll; + int ch, erasec, killc; color_t color; mvaddstr(LINES - 1, 0, "search:"); oldsel = rover.fsel; oldscroll = rover.scroll; *SEARCH = '\0'; length = 0; + erasec = erasechar(); + killc = killchar(); while (1) { ch = getch(); - key = keyname(ch); - if (!strcmp(key, "^M")) + if (ch == '\r' || ch == '\n' || ch == KEY_DOWN || ch == KEY_ENTER) break; - else if ( - !strcmp(key, "^G") || !strcmp(key, "^?") || - !strcmp(key, "^H") || !strcmp(key, "^X") - ) { + else if (ch == erasec || ch == KEY_LEFT || ch == KEY_BACKSPACE) { if (length) SEARCH[--length] = '\0'; if (!length) { @@ -371,6 +370,12 @@ main() rover.scroll = oldscroll; } } + else if (ch == killc) { + length = 0; + SEARCH[0] = '\0'; + rover.fsel = oldsel; + rover.scroll = oldscroll; + } else if (length < SEARCHSZ - 2) { SEARCH[length++] = ch; SEARCH[length+1] = '\0';