You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ma...@apache.org on 2016/03/02 00:40:11 UTC
[1/2] incubator-mynewt-larva git commit: Fix bug;
crashing on no input.
Repository: incubator-mynewt-larva
Updated Branches:
refs/heads/develop 2e28d273b -> ef317077d
Fix bug; crashing on no input.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/commit/c7e5c93a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/c7e5c93a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/c7e5c93a
Branch: refs/heads/develop
Commit: c7e5c93a93ba3abac04480cd22a0f9ca0c593d98
Parents: 2e28d27
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue Mar 1 15:36:44 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Tue Mar 1 15:36:44 2016 -0800
----------------------------------------------------------------------
libs/shell/src/shell.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/c7e5c93a/libs/shell/src/shell.c
----------------------------------------------------------------------
diff --git a/libs/shell/src/shell.c b/libs/shell/src/shell.c
index 70ae046..fe5f138 100644
--- a/libs/shell/src/shell.c
+++ b/libs/shell/src/shell.c
@@ -161,7 +161,7 @@ err:
return (rc);
}
-static int
+static int
shell_process_command(char *line, int len)
{
char *tok;
@@ -180,13 +180,14 @@ shell_process_command(char *line, int len)
/* Terminate the argument list with a null pointer. */
argv[argc] = NULL;
- (void) shell_cmd(argv[0], argv, argc);
-
+ if (argc) {
+ (void) shell_cmd(argv[0], argv, argc);
+ }
return (0);
}
-static int
+static int
shell_nlip_process(char *data, int len)
{
uint16_t copy_len;
@@ -367,7 +368,7 @@ err:
return (rc);
}
-static int
+static int
shell_read_console(void)
{
int rc;
@@ -386,7 +387,7 @@ shell_read_console(void)
shell_line_len = 0;
shell_full_line = 0;
if (rc > 2) {
- if (shell_line[0] == SHELL_NLIP_PKT_START1 &&
+ if (shell_line[0] == SHELL_NLIP_PKT_START1 &&
shell_line[1] == SHELL_NLIP_PKT_START2) {
if (g_nlip_mbuf) {
os_mbuf_free_chain(g_nlip_mbuf);
@@ -395,7 +396,7 @@ shell_read_console(void)
g_nlip_expected_len = 0;
rc = shell_nlip_process(&shell_line[2], rc-2);
- } else if (shell_line[0] == SHELL_NLIP_DATA_START1 &&
+ } else if (shell_line[0] == SHELL_NLIP_DATA_START1 &&
shell_line[1] == SHELL_NLIP_DATA_START2) {
rc = shell_nlip_process(&shell_line[2], rc-2);
} else {
[2/2] incubator-mynewt-larva git commit: Treat 'del' and left-arrow
like backspace. Right-arrow inserts space, up/down arrows do nothing.
Posted by ma...@apache.org.
Treat 'del' and left-arrow like backspace. Right-arrow inserts space,
up/down arrows do nothing.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/commit/ef317077
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/ef317077
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/ef317077
Branch: refs/heads/develop
Commit: ef317077d66b574c5b586e3c05cffd2eb2ee356e
Parents: c7e5c93
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue Mar 1 15:38:42 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Tue Mar 1 15:38:42 2016 -0800
----------------------------------------------------------------------
libs/console/full/src/cons_tty.c | 75 ++++++++++++++++++++++++++++++-----
1 file changed, 65 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ef317077/libs/console/full/src/cons_tty.c
----------------------------------------------------------------------
diff --git a/libs/console/full/src/cons_tty.c b/libs/console/full/src/cons_tty.c
index 88597e9..2d254e4 100644
--- a/libs/console/full/src/cons_tty.c
+++ b/libs/console/full/src/cons_tty.c
@@ -6,7 +6,7 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
@@ -31,6 +31,14 @@ int console_is_midline;
#define CONSOLE_TX_BUF_SZ 32 /* IO buffering, must be power of 2 */
#define CONSOLE_RX_BUF_SZ 128
+
+#define CONSOLE_DEL 0x7f /* del character */
+#define CONSOLE_ESC 0x1b /* esc character */
+#define CONSOLE_LEFT 'D' /* esc-[-D emitted when moving left */
+#define CONSOLE_UP 'A' /* esc-[-A moving up */
+#define CONSOLE_RIGHT 'C' /* esc-[-C moving right */
+#define CONSOLE_DOWN 'B' /* esc-[-B moving down */
+
#define CONSOLE_HEAD_INC(cr) (((cr)->cr_head + 1) & ((cr)->cr_size - 1))
#define CONSOLE_TAIL_INC(cr) (((cr)->cr_tail + 1) & ((cr)->cr_size - 1))
@@ -52,6 +60,7 @@ struct console_tty {
console_rx_cb ct_rx_cb; /* callback that input is ready */
console_write_char ct_write_char;
uint8_t ct_echo_off:1;
+ uint8_t ct_esc_seq:2;
} console_tty;
static void
@@ -71,11 +80,14 @@ console_pull_char(struct console_ring *cr)
return ch;
}
-static void
+static int
console_pull_char_head(struct console_ring *cr)
{
if (cr->cr_head != cr->cr_tail) {
cr->cr_head = (cr->cr_head - 1) & (cr->cr_size - 1);
+ return 0;
+ } else {
+ return -1;
}
}
@@ -254,21 +266,63 @@ console_rx_char(void *arg, uint8_t data)
ct->ct_rx_cb(1);
}
break;
+ case CONSOLE_ESC:
+ ct->ct_esc_seq = 1;
+ goto out;
+ case '[':
+ if (ct->ct_esc_seq == 1) {
+ ct->ct_esc_seq = 2;
+ goto out;
+ } else {
+ goto queue_char;
+ }
+ break;
+ case CONSOLE_LEFT:
+ if (ct->ct_esc_seq == 2) {
+ goto backspace;
+ } else {
+ goto queue_char;
+ }
+ break;
+ case CONSOLE_UP:
+ case CONSOLE_DOWN:
+ if (ct->ct_esc_seq == 2) {
+ /*
+ * Do nothing.
+ */
+ ct->ct_esc_seq = 0;
+ goto out;
+ }
+ goto queue_char;
+ case CONSOLE_RIGHT:
+ if (ct->ct_esc_seq == 2) {
+ data = ' '; /* add space */
+ }
+ goto queue_char;
case '\b':
+ case CONSOLE_DEL:
+backspace:
/*
* backspace
*/
- tx_buf[0] = '\b';
- tx_buf[1] = ' ';
- tx_buf[2] = '\b';
- tx_space = 3;
- console_pull_char_head(rx);
+ ct->ct_esc_seq = 0;
+ if (console_pull_char_head(rx) == 0) {
+ /*
+ * Only wipe out char if we can pull stuff off from head.
+ */
+ tx_buf[0] = '\b';
+ tx_buf[1] = ' ';
+ tx_buf[2] = '\b';
+ tx_space = 3;
+ } else {
+ goto out;
+ }
break;
default:
+queue_char:
tx_buf[0] = data;
tx_space = 1;
- if (!ct->ct_echo_off) {
- }
+ ct->ct_esc_seq = 0;
console_add_char(rx, data);
break;
}
@@ -281,10 +335,11 @@ console_rx_char(void *arg, uint8_t data)
}
hal_uart_start_tx(CONSOLE_UART);
}
+out:
return 0;
}
-int
+int
console_is_init(void)
{
return (g_console_is_init);