stmhal: Add home/end cursor support in readline.
Home/end work in picocom and screen (different codes in those 2 programs). Also, CTRL-A (for non-empty liny) and CTRL-E act as home/end.
This commit is contained in:
parent
3269cf2f93
commit
3996611c1b
@ -31,6 +31,7 @@ int readline(vstr_t *line, const char *prompt) {
|
||||
stdout_tx_str(prompt);
|
||||
int orig_line_len = line->len;
|
||||
int escape_seq = 0;
|
||||
char escape_seq_buf[1] = {0};
|
||||
int hist_cur = -1;
|
||||
int cursor_pos = orig_line_len;
|
||||
for (;;) {
|
||||
@ -43,6 +44,12 @@ int readline(vstr_t *line, const char *prompt) {
|
||||
if (VCP_CHAR_CTRL_A <= c && c <= VCP_CHAR_CTRL_D && vstr_len(line) == orig_line_len) {
|
||||
// control character with empty line
|
||||
return c;
|
||||
} else if (c == VCP_CHAR_CTRL_A) {
|
||||
// CTRL-A with non-empty line is go-to-start-of-line
|
||||
redraw_step_back = cursor_pos - orig_line_len;
|
||||
} else if (c == VCP_CHAR_CTRL_E) {
|
||||
// CTRL-E is go-to-end-of-line
|
||||
redraw_step_forward = line->len - cursor_pos;
|
||||
} else if (c == '\r') {
|
||||
// newline
|
||||
stdout_tx_str("\r\n");
|
||||
@ -80,6 +87,10 @@ int readline(vstr_t *line, const char *prompt) {
|
||||
escape_seq = 0;
|
||||
}
|
||||
} else if (escape_seq == 2) {
|
||||
if ('0' <= c && c <= '9') {
|
||||
escape_seq = 3;
|
||||
escape_seq_buf[0] = c;
|
||||
} else {
|
||||
escape_seq = 0;
|
||||
if (c == 'A') {
|
||||
// up arrow
|
||||
@ -120,6 +131,18 @@ int readline(vstr_t *line, const char *prompt) {
|
||||
redraw_step_back = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (escape_seq == 3) {
|
||||
escape_seq = 0;
|
||||
if (c == '~') {
|
||||
if (escape_seq_buf[0] == '1' || escape_seq_buf[0] == '7') {
|
||||
// home key
|
||||
redraw_step_back = cursor_pos - orig_line_len;
|
||||
} else if (escape_seq_buf[0] == '4' || escape_seq_buf[0] == '8') {
|
||||
// end key
|
||||
redraw_step_forward = line->len - cursor_pos;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
escape_seq = 0;
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
#define VCP_CHAR_CTRL_B (2)
|
||||
#define VCP_CHAR_CTRL_C (3)
|
||||
#define VCP_CHAR_CTRL_D (4)
|
||||
#define VCP_CHAR_CTRL_E (5)
|
||||
|
||||
typedef enum {
|
||||
USB_DEVICE_MODE_CDC_MSC,
|
||||
|
Loading…
Reference in New Issue
Block a user