X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=linenoise.c;h=9740366afd4ab3bac7329f38feef002101fe0b89;hb=d9d8f323ca04ca6a5546f176ea5f5d0d745d6b66;hp=8615508aa759382d8c7f76e0607992090ebe3b4d;hpb=68743b5bf372beb92fd0c81f791690711fabc148;p=linenoise.git diff --git a/linenoise.c b/linenoise.c index 8615508..9740366 100644 --- a/linenoise.c +++ b/linenoise.c @@ -453,16 +453,22 @@ static int check_special(int fd) return SPECIAL_HOME; } } - if (c == '[' && c2 >= '1' && c2 <= '6') { + if (c == '[' && c2 >= '1' && c2 <= '8') { /* extended escape */ - int c3 = fd_read_char(fd, 50); - if (c2 == '3' && c3 == '~') { - /* delete char under cursor */ - return SPECIAL_DELETE; + c = fd_read_char(fd, 50); + if (c == '~') { + switch (c2) { + case '3': + return SPECIAL_DELETE; + case '7': + return SPECIAL_HOME; + case '8': + return SPECIAL_END; + } } - while (c3 != -1 && c3 != '~') { + while (c != -1 && c != '~') { /* .e.g \e[12~ or '\e[11;2~ discard the complete sequence */ - c3 = fd_read_char(fd, 50); + c = fd_read_char(fd, 50); } } @@ -975,8 +981,9 @@ process_char: free(history[history_len]); return -1; } - /* Otherwise delete char to right of cursor */ - if (remove_char(current, current->pos)) { + /* Otherwise fall through to delete char to right of cursor */ + case SPECIAL_DELETE: + if (remove_char(current, current->pos) == 1) { refreshLine(current->prompt, current); } break; @@ -1162,28 +1169,16 @@ process_char: refreshLine(current->prompt, current); } break; - - case SPECIAL_DELETE: - if (remove_char(current, current->pos) == 1) { - refreshLine(current->prompt, current); - } - break; + case ctrl('A'): /* Ctrl+a, go to the start of the line */ case SPECIAL_HOME: current->pos = 0; refreshLine(current->prompt, current); break; + case ctrl('E'): /* ctrl+e, go to the end of the line */ case SPECIAL_END: current->pos = current->chars; refreshLine(current->prompt, current); break; - default: - /* Only tab is allowed without ^V */ - if (c == '\t' || c >= ' ') { - if (insert_char(current, current->pos, c) == 1) { - refreshLine(current->prompt, current); - } - } - break; case ctrl('U'): /* Ctrl+u, delete to beginning of line. */ if (remove_chars(current, 0, current->pos)) { refreshLine(current->prompt, current); @@ -1194,21 +1189,20 @@ process_char: refreshLine(current->prompt, current); } break; - case ctrl('A'): /* Ctrl+a, go to the start of the line */ - current->pos = 0; - refreshLine(current->prompt, current); - break; - case ctrl('E'): /* ctrl+e, go to the end of the line */ - current->pos = current->chars; - refreshLine(current->prompt, current); - break; case ctrl('L'): /* Ctrl+L, clear screen */ - /* clear screen */ clearScreen(current); /* Force recalc of window size for serial terminals */ current->cols = 0; refreshLine(current->prompt, current); break; + default: + /* Only tab is allowed without ^V */ + if (c == '\t' || c >= ' ') { + if (insert_char(current, current->pos, c) == 1) { + refreshLine(current->prompt, current); + } + } + break; } } return current->len;