uart: support backspace for RX input

This commit is contained in:
Zihao Yu 2024-01-09 03:35:40 +08:00
parent 7007a7b2cc
commit 43c32540e9
3 changed files with 16 additions and 5 deletions

View File

@ -52,8 +52,11 @@ void read_event() {
case SDL_MOUSEBUTTONDOWN: mousedown_handler(ev); break;
case SDL_MOUSEBUTTONUP: mouseup_handler(ev); break;
case SDL_KEYDOWN:
if (ev.key.keysym.sym == SDLK_RETURN && focus_uart_rx_term) {
uart_rx_getchar('\n');
if (focus_uart_rx_term) {
switch (ev.key.keysym.sym) {
case SDLK_RETURN: uart_rx_getchar('\n'); break;
case SDLK_BACKSPACE: uart_rx_getchar('\b'); break;
}
}
case SDL_KEYUP:
if (!focus_uart_rx_term) kb_push_key(ev.key.keysym.scancode, ev.key.type == SDL_KEYDOWN);

View File

@ -80,9 +80,13 @@ void Term::feed_ch(uint8_t ch) {
if (ch == '\n') {
newline();
return;
} else if (ch == '\b') {
if (cursor_x > 0) cursor_x --; // FIXME: back to the last line for input
lines[y][cursor_x] = ' ';
if (is_cursor_on_screen()) set_dirty_char(cursor_y - screen_y, cursor_x);
return;
}
uint8_t *l = lines[y];
l[cursor_x] = ch;
lines[y][cursor_x] = ch;
cursor_x ++;
if (cursor_x == w_in_char) newline();
}

View File

@ -90,7 +90,11 @@ void UART::rx_getchar(uint8_t ch) {
rx_input = "";
}
else {
rx_input += ch;
if (ch == '\b') {
if (rx_input.empty()) return;
rx_input.pop_back();
}
else { rx_input += ch; }
rx_term->feed_ch(ch);
}
rx_update_gui = true;