summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJari Vetoniemi <mailroxas@gmail.com>2018-10-22 22:36:11 +0300
committerJari Vetoniemi <mailroxas@gmail.com>2018-10-22 22:36:11 +0300
commitcc236f1bf6fb01db55cb36781f14bf5fbd97b061 (patch)
tree50465c565b4bc298aa38f4bb7f72646a59edc0fc
parent55511a35156b3de7b7baef58b844d9b800d4ba3a (diff)
memview: fix some bugs in the input()
-rw-r--r--src/memview.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/memview.c b/src/memview.c
index eb61106..0f07cba 100644
--- a/src/memview.c
+++ b/src/memview.c
@@ -478,22 +478,24 @@ input(const char *prompt)
{
static char input[255];
memset(input, 0, sizeof(input));
- for (unsigned char i = 0; (size_t)i + 1 < sizeof(input); i += input[i] != 0) {
+ for (unsigned char i = 0;;) {
screen_cursor(0, ctx.term.ws.h);
screen_print(ESCA CLEAR_LINE);
screen_printf(FMT(FG YELLOW) "%s" FMT(PLAIN) " %s", prompt, input);
screen_flush();
fread(input + i, 1, 1, TERM_STREAM);
-
switch (input[i]) {
case 0x7f:
- input[(i > 0 ? --i : 0)] = 0;
+ input[(i > 0 ? i-- : 0)] = 0;
break;
case 0x04:
case 0x1b:
return NULL;
case '\n':
+ input[i] = 0;
goto out;
+ default:
+ i += (i < sizeof(input) && (unsigned int)snprintf(NULL, 0, "%s %s", prompt, input) < ctx.term.ws.w);
}
}