Rev 4239 | Rev 4264 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4239 | Rev 4255 | ||
---|---|---|---|
Line 34... | Line 34... | ||
34 | #include <string.h> |
34 | #include <string.h> |
35 | #include <io/stream.h> |
35 | #include <io/stream.h> |
36 | #include <console.h> |
36 | #include <console.h> |
37 | #include <kbd/kbd.h> |
37 | #include <kbd/kbd.h> |
38 | #include <kbd/keycode.h> |
38 | #include <kbd/keycode.h> |
- | 39 | #include <errno.h> |
|
- | 40 | #include <bool.h> |
|
39 | 41 | ||
40 | #include "config.h" |
42 | #include "config.h" |
41 | #include "util.h" |
43 | #include "util.h" |
42 | #include "scli.h" |
44 | #include "scli.h" |
43 | #include "input.h" |
45 | #include "input.h" |
Line 97... | Line 99... | ||
97 | } |
99 | } |
98 | 100 | ||
99 | static void read_line(char *buffer, int n) |
101 | static void read_line(char *buffer, int n) |
100 | { |
102 | { |
101 | kbd_event_t ev; |
103 | kbd_event_t ev; |
- | 104 | size_t offs, otmp; |
|
102 | int chars; |
105 | wchar_t dec; |
103 | 106 | ||
104 | chars = 0; |
107 | offs = 0; |
105 | while (chars < n - 1) { |
108 | while (true) { |
106 | fflush(stdout); |
109 | fflush(stdout); |
107 | if (kbd_get_event(&ev) < 0) |
110 | if (kbd_get_event(&ev) < 0) |
108 | return; |
111 | return; |
109 | if (ev.type == KE_RELEASE) |
112 | if (ev.type == KE_RELEASE) |
110 | continue; |
113 | continue; |
111 | 114 | ||
112 | if (ev.key == KC_ENTER || ev.key == KC_NENTER) |
115 | if (ev.key == KC_ENTER || ev.key == KC_NENTER) |
113 | break; |
116 | break; |
114 | if (ev.key == KC_BACKSPACE) { |
117 | if (ev.key == KC_BACKSPACE) { |
115 | if (chars > 0) { |
118 | if (offs > 0) { |
- | 119 | /* |
|
- | 120 | * Back up until we reach valid start of |
|
- | 121 | * character. |
|
- | 122 | */ |
|
- | 123 | while (offs > 0) { |
|
- | 124 | --offs; otmp = offs; |
|
- | 125 | dec = str_decode(buffer, &otmp, n); |
|
- | 126 | if (dec != U_SPECIAL) |
|
- | 127 | break; |
|
- | 128 | } |
|
116 | putchar('\b'); |
129 | putchar('\b'); |
117 | --chars; |
- | |
118 | } |
130 | } |
119 | continue; |
131 | continue; |
120 | } |
132 | } |
121 | if (ev.c >= ' ') { |
133 | if (ev.c >= ' ') { |
122 | //putchar(ev.c); |
134 | //putchar(ev.c); |
- | 135 | if (chr_encode(ev.c, buffer, &offs, n - 1) == EOK) |
|
123 | console_putchar(ev.c); |
136 | console_putchar(ev.c); |
124 | buffer[chars++] = ev.c; |
- | |
125 | } |
137 | } |
126 | } |
138 | } |
127 | putchar('\n'); |
139 | putchar('\n'); |
128 | buffer[chars] = '\0'; |
140 | buffer[offs] = '\0'; |
129 | } |
141 | } |
130 | 142 | ||
131 | /* TODO: |
143 | /* TODO: |
132 | * Implement something like editline() / readline(), if even |
144 | * Implement something like editline() / readline(), if even |
133 | * just for command history and making arrows work. */ |
145 | * just for command history and making arrows work. */ |