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" |
57,7 → 61,7 |
if (NULL == usr->line) |
return CL_EFAIL; |
|
tmp = strdup(usr->line); |
tmp = str_dup(usr->line); |
|
cmd[n] = strtok(tmp, " "); |
while (cmd[n] && n < WORD_MAX) { |
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: |
128,7 → 146,6 |
void get_input(cliuser_t *usr) |
{ |
char line[INPUT_MAX]; |
size_t len = 0; |
|
console_set_style(STYLE_EMPHASIS); |
printf("%s", usr->prompt); |
135,11 → 152,10 |
console_set_style(STYLE_NORMAL); |
|
read_line(line, INPUT_MAX); |
len = strlen(line); |
/* Make sure we don't have rubbish or a C/R happy user */ |
if (len == 0 || line[0] == '\n') |
if (str_cmp(line, "") == 0 || str_cmp(line, "\n") == 0) |
return; |
usr->line = strdup(line); |
usr->line = str_dup(line); |
|
return; |
} |