Add backspacing to prompt
This commit is contained in:
parent
697a764ae8
commit
bb637bab94
2 changed files with 21 additions and 10 deletions
|
@ -31,6 +31,7 @@ void input_process_key(KEY c) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CTRL_KEY('L'):
|
case CTRL_KEY('L'):
|
||||||
|
case ESCAPE:
|
||||||
case NOP:
|
case NOP:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
30
src/kilo.c
30
src/kilo.c
|
@ -71,17 +71,27 @@ char *editor_prompt(const char *prompt) {
|
||||||
ui_draw_screen();
|
ui_draw_screen();
|
||||||
|
|
||||||
KEY key = terminal_read_key();
|
KEY key = terminal_read_key();
|
||||||
if (key == ESCAPE) goto failure;
|
switch (key) {
|
||||||
else if (key == ENTER) {
|
case BACKSPACE:
|
||||||
if (buf_size > 0) goto success;
|
if (buf_size > 0)
|
||||||
else goto failure;
|
buf[--buf_size] = '\0';
|
||||||
} else if (isprint(key)) {
|
break;
|
||||||
if (buf_size + 1 >= buf_cap)
|
case ENTER:
|
||||||
buf = realloc(buf, buf_cap *= 2);
|
if (buf_size > 0) goto success;
|
||||||
|
else goto failure;
|
||||||
|
break;
|
||||||
|
case ESCAPE:
|
||||||
|
goto failure;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if (isprint(key)) {
|
||||||
|
if (buf_size + 1 >= buf_cap)
|
||||||
|
buf = realloc(buf, buf_cap *= 2);
|
||||||
|
|
||||||
buf[buf_size] = key;
|
buf[buf_size] = key;
|
||||||
buf_size++;
|
buf_size++;
|
||||||
buf[buf_size] = '\0';
|
buf[buf_size] = '\0';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue