Skip to content
Snippets Groups Projects
Commit 3996611c authored by Damien George's avatar Damien George
Browse files

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.
parent 3269cf2f
No related branches found
No related tags found
No related merge requests found
...@@ -31,6 +31,7 @@ int readline(vstr_t *line, const char *prompt) { ...@@ -31,6 +31,7 @@ int readline(vstr_t *line, const char *prompt) {
stdout_tx_str(prompt); stdout_tx_str(prompt);
int orig_line_len = line->len; int orig_line_len = line->len;
int escape_seq = 0; int escape_seq = 0;
char escape_seq_buf[1] = {0};
int hist_cur = -1; int hist_cur = -1;
int cursor_pos = orig_line_len; int cursor_pos = orig_line_len;
for (;;) { for (;;) {
...@@ -43,6 +44,12 @@ int readline(vstr_t *line, const char *prompt) { ...@@ -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) { if (VCP_CHAR_CTRL_A <= c && c <= VCP_CHAR_CTRL_D && vstr_len(line) == orig_line_len) {
// control character with empty line // control character with empty line
return c; 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') { } else if (c == '\r') {
// newline // newline
stdout_tx_str("\r\n"); stdout_tx_str("\r\n");
...@@ -80,6 +87,10 @@ int readline(vstr_t *line, const char *prompt) { ...@@ -80,6 +87,10 @@ int readline(vstr_t *line, const char *prompt) {
escape_seq = 0; escape_seq = 0;
} }
} else if (escape_seq == 2) { } else if (escape_seq == 2) {
if ('0' <= c && c <= '9') {
escape_seq = 3;
escape_seq_buf[0] = c;
} else {
escape_seq = 0; escape_seq = 0;
if (c == 'A') { if (c == 'A') {
// up arrow // up arrow
...@@ -120,6 +131,18 @@ int readline(vstr_t *line, const char *prompt) { ...@@ -120,6 +131,18 @@ int readline(vstr_t *line, const char *prompt) {
redraw_step_back = 1; 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 { } else {
escape_seq = 0; escape_seq = 0;
} }
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#define VCP_CHAR_CTRL_B (2) #define VCP_CHAR_CTRL_B (2)
#define VCP_CHAR_CTRL_C (3) #define VCP_CHAR_CTRL_C (3)
#define VCP_CHAR_CTRL_D (4) #define VCP_CHAR_CTRL_D (4)
#define VCP_CHAR_CTRL_E (5)
typedef enum { typedef enum {
USB_DEVICE_MODE_CDC_MSC, USB_DEVICE_MODE_CDC_MSC,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment