34,6 → 34,10 |
#include <string.h> |
#include <io/stream.h> |
#include <console.h> |
#include <kbd/kbd.h> |
#include <kbd/keycode.h> |
#include <errno.h> |
#include <bool.h> |
|
#include "config.h" |
#include "util.h" |
96,30 → 100,44 |
|
static void read_line(char *buffer, int n) |
{ |
char c; |
int chars; |
kbd_event_t ev; |
size_t offs, otmp; |
wchar_t dec; |
|
chars = 0; |
while (chars < n - 1) { |
c = getchar(); |
if (c < 0) |
offs = 0; |
while (true) { |
fflush(stdout); |
if (kbd_get_event(&ev) < 0) |
return; |
if (c == '\n') |
if (ev.type == KE_RELEASE) |
continue; |
|
if (ev.key == KC_ENTER || ev.key == KC_NENTER) |
break; |
if (c == '\b') { |
if (chars > 0) { |
if (ev.key == KC_BACKSPACE) { |
if (offs > 0) { |
/* |
* Back up until we reach valid start of |
* character. |
*/ |
while (offs > 0) { |
--offs; otmp = offs; |
dec = str_decode(buffer, &otmp, n); |
if (dec != U_SPECIAL) |
break; |
} |
putchar('\b'); |
--chars; |
} |
continue; |
} |
if (c >= ' ') { |
putchar(c); |
buffer[chars++] = c; |
if (ev.c >= ' ') { |
//putchar(ev.c); |
if (chr_encode(ev.c, buffer, &offs, n - 1) == EOK) |
console_putchar(ev.c); |
} |
} |
putchar('\n'); |
buffer[chars] = '\0'; |
buffer[offs] = '\0'; |
} |
|
/* TODO: |