You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by je...@apache.org on 2019/10/17 11:47:27 UTC
[mynewt-core] 19/21: sys/console: Fix handling of home/end keys for
putty
This is an automated email from the ASF dual-hosted git repository.
jerzy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit d9fe8025648d896d861730c224ab076767c88429
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Wed Oct 9 16:25:32 2019 +0200
sys/console: Fix handling of home/end keys for putty
There was code to handle home and keys but it was not
working at on putty terminal.
---
sys/console/full/src/console.c | 58 +++++++++++++++++++++++++++++-------------
1 file changed, 40 insertions(+), 18 deletions(-)
diff --git a/sys/console/full/src/console.c b/sys/console/full/src/console.c
index 438fef7..f311fc8 100644
--- a/sys/console/full/src/console.c
+++ b/sys/console/full/src/console.c
@@ -836,6 +836,34 @@ console_hist_move(char *line, uint8_t direction)
#endif
static void
+handle_home(void)
+{
+ if (cur) {
+ cursor_backward(cur);
+ trailing_chars += cur;
+ cur = 0;
+ }
+}
+
+static void
+handle_delete(char *line)
+{
+ if (trailing_chars) {
+ del_char(&line[cur]);
+ }
+}
+
+static void
+handle_end(void)
+{
+ if (trailing_chars) {
+ cursor_forward(trailing_chars);
+ cur += trailing_chars;
+ trailing_chars = 0;
+ }
+}
+
+static void
handle_ansi(uint8_t byte, char *line)
{
if (esc_state & ESC_ANSI_FIRST) {
@@ -906,29 +934,23 @@ ansi_cmd:
cursor_forward(ansi_val);
break;
case ANSI_HOME:
- if (!cur) {
- break;
- }
-
- cursor_backward(cur);
- trailing_chars += cur;
- cur = 0;
+ handle_home();
break;
case ANSI_END:
- if (!trailing_chars) {
- break;
- }
-
- cursor_forward(trailing_chars);
- cur += trailing_chars;
- trailing_chars = 0;
+ handle_end();
break;
- case ANSI_DEL:
- if (!trailing_chars) {
+ case '~':
+ switch (ansi_val) {
+ case 1:
+ handle_home();
+ break;
+ case 3:
+ handle_delete(line);
+ break;
+ case 4:
+ handle_end();
break;
}
-
- del_char(&line[cur]);
break;
case DSR_CPS:
if (MYNEWT_VAL(CONSOLE_STICKY_PROMPT) && terminal_size_requested) {