summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/kernel/core/kmain.cpp2
-rw-r--r--src/kernel/ui/vt.cpp4
-rw-r--r--src/user/lib/libc/std/readline.c107
3 files changed, 69 insertions, 44 deletions
diff --git a/src/kernel/core/kmain.cpp b/src/kernel/core/kmain.cpp
index 05d7966..23b62e3 100644
--- a/src/kernel/core/kmain.cpp
+++ b/src/kernel/core/kmain.cpp
@@ -48,7 +48,7 @@ extern "C" void kmain(multiboot_info_t* mbd, int32_t magic) {
_no_more_ksbrk = true;
// Init higher level stuff
- timer_init(30);
+ timer_init(100);
tasking_init();
vfs_setup();
diff --git a/src/kernel/ui/vt.cpp b/src/kernel/ui/vt.cpp
index 9b0bdf0..3bed897 100644
--- a/src/kernel/ui/vt.cpp
+++ b/src/kernel/ui/vt.cpp
@@ -384,8 +384,8 @@ int vt::read(size_t offset, size_t len, char* buffer) {
if (c == len) break;
}
} else {
- for (; r < kbd_buffer_filled && c < len; r++) {
- buffer[c++] = kbd_buffer[r];
+ while (r < kbd_buffer_filled && c < len) {
+ buffer[c++] = kbd_buffer[r++];
}
end = true;
}
diff --git a/src/user/lib/libc/std/readline.c b/src/user/lib/libc/std/readline.c
index ab13189..5cd9119 100644
--- a/src/user/lib/libc/std/readline.c
+++ b/src/user/lib/libc/std/readline.c
@@ -81,50 +81,57 @@ char *freadline(FILE f, readline_history *h) {
int l = read(f, 0, 16, buf);
if (l < 0) return 0;
- if (buf[0] == 27) {
- if (buf[1] == '[') {
- if (buf[2] == 'A') { // up
- if (lid > 0) {
- lid--;
- str = h->str[lid];
- len = strlen(str);
- cur = str + len;
+ char *in = buf;
+ while (in < buf + l) {
+ if (*in == 27) {
+ in++;
+ if (*in == '[') {
+ in++;
+ if (*in == 'A') { // up
+ if (lid > 0) {
+ lid--;
+ str = h->str[lid];
+ len = strlen(str);
+ cur = str + len;
+ }
+ } else if (*in == 'B') { // down
+ if (lid < h->n - 1) {
+ lid++;
+ str = h->str[lid];
+ len = strlen(str);
+ cur = str + len;
+ }
+ } else if (*in == 'C') { // forward (right)
+ if (cur < str + len) cur++;
+ } else if (*in == 'D') { // back (left)
+ if (cur > str) cur--;
}
- } else if (buf[2] == 'B') { // down
- if (lid < h->n - 1) {
- lid++;
- str = h->str[lid];
- len = strlen(str);
- cur = str + len;
- }
- } else if (buf[2] == 'C') { // forward (right)
- if (cur < str + len) cur++;
- } else if (buf[2] == 'D') { // back (left)
- if (cur > str) cur--;
+ } else {
+ // ALT sequence - ignore
+ in++;
+ }
+ } else if (*in == '\n') {
+ finished = 1;
+ cur = str + len;
+ } else if (*in == '\b') {
+ if (cur > str) {
+ cur--;
+ len--;
+ char* c;
+ for (c = cur; *c != 0; c++) c[0] = c[1];
+ }
+ } else if (*in == '\t') {
+ // ignore tabs -- todo: tab completion???? haha
+ } else if (*in >= ' ') {
+ if (l < 255) {
+ char* c;
+ for (c = cur + len; c >= cur; c--) c[1] = c[0];
+ cur[0] = *in;
+ cur++;
+ len++;
}
- } else {
- // ALT sequence - ignore
- }
- } else if (buf[0] == '\n') {
- finished = 1;
- cur = str + len;
- } else if (buf[0] == '\b') {
- if (cur > str) {
- cur--;
- len--;
- char* c;
- for (c = cur; *c != 0; c++) c[0] = c[1];
- }
- } else if (buf[0] == '\t') {
- // ignore tabs -- todo: tab completion???? haha
- } else if (buf[0] >= ' ') {
- if (l < 255) {
- char* c;
- for (c = cur + len; c >= cur; c--) c[1] = c[0];
- cur[0] = buf[0];
- cur++;
- len++;
}
+ in++;
}
// ASSUMPTION : everything will fit on one line...
@@ -136,7 +143,25 @@ char *freadline(FILE f, readline_history *h) {
if (finished) {
fprintf(f, "\n");
+
+ if (h->str[h->n-1] != str) h->n--;
+
+ i = h->n - 1;
+ while (h->str[i] != str) {
+ if (i == 0) {
+ fprint(f, "READLINE FAIL");
+ return 0;
+ }
+ i--;
+ }
+ while (i < h->n - 1) {
+ h->str[i] = h->str[i+1];
+ i++;
+ }
+ h->str[i] = str;
+
if (h->str[h->n-1][0] == 0) h->n--;
+
return str;
}
}