|
@@ -10,6 +10,7 @@
|
10
|
10
|
#include "log.h"
|
11
|
11
|
#include "pmw3360.h"
|
12
|
12
|
#include "util.h"
|
|
13
|
+#include "usb_cdc.h"
|
13
|
14
|
#include "usb_msc.h"
|
14
|
15
|
#include "debug.h"
|
15
|
16
|
#include "console.h"
|
|
@@ -214,6 +215,32 @@ void cnsl_handle_input(const char *buf, uint32_t len) {
|
214
|
215
|
memcpy(cnsl_line_buff + cnsl_buff_pos, buf, len);
|
215
|
216
|
cnsl_buff_pos += len;
|
216
|
217
|
|
|
218
|
+ // handle backspace
|
|
219
|
+ for (ssize_t i = cnsl_buff_pos - len; i < (ssize_t)cnsl_buff_pos; i++) {
|
|
220
|
+ if ((cnsl_line_buff[i] == '\b') || (cnsl_line_buff[i] == 0x7F)) {
|
|
221
|
+ if (i > 0) {
|
|
222
|
+ // overwrite previous character and backspace
|
|
223
|
+ for (ssize_t j = i; j < (ssize_t)cnsl_buff_pos - 1; j++) {
|
|
224
|
+ cnsl_line_buff[j - 1] = cnsl_line_buff[j + 1];
|
|
225
|
+ }
|
|
226
|
+ cnsl_buff_pos -= 2;
|
|
227
|
+ } else {
|
|
228
|
+ // just remove the backspace
|
|
229
|
+ for (ssize_t j = i; j < (ssize_t)cnsl_buff_pos - 1; j++) {
|
|
230
|
+ cnsl_line_buff[j] = cnsl_line_buff[j + 1];
|
|
231
|
+ }
|
|
232
|
+ cnsl_buff_pos -= 1;
|
|
233
|
+ }
|
|
234
|
+
|
|
235
|
+ usb_cdc_write("\b \b", 3);
|
|
236
|
+
|
|
237
|
+ // check for another backspace in this space
|
|
238
|
+ i--;
|
|
239
|
+ } else {
|
|
240
|
+ usb_cdc_write(cnsl_line_buff + i, 1);
|
|
241
|
+ }
|
|
242
|
+ }
|
|
243
|
+
|
217
|
244
|
int32_t line_len = cnsl_find_line_end();
|
218
|
245
|
if (line_len < 0) {
|
219
|
246
|
// user has not pressed enter yet
|
|
@@ -223,8 +250,6 @@ void cnsl_handle_input(const char *buf, uint32_t len) {
|
223
|
250
|
// convert line to C-style string
|
224
|
251
|
cnsl_line_buff[line_len] = '\0';
|
225
|
252
|
|
226
|
|
- // TODO handle backspace and other terminal commands?
|
227
|
|
-
|
228
|
253
|
cnsl_interpret(cnsl_line_buff);
|
229
|
254
|
|
230
|
255
|
// store command for eventual repeats
|