summaryrefslogtreecommitdiffstats
path: root/sh/input.c
diff options
context:
space:
mode:
authorJack Palevich <jackpal@google.com>2010-05-25 14:49:57 +0800
committerJack Palevich <jackpal@google.com>2010-05-25 14:49:57 +0800
commit7fe202f160ca1926bc0277e3c276ad7b3f9b9aeb (patch)
tree3c962cbc42d5604c809ebefb8116174582b6f7bf /sh/input.c
parentd9d1ca47802395e9e42e7deb05b2683d9d306598 (diff)
downloadcore-7fe202f160ca1926bc0277e3c276ad7b3f9b9aeb.tar.gz
core-7fe202f160ca1926bc0277e3c276ad7b3f9b9aeb.tar.bz2
core-7fe202f160ca1926bc0277e3c276ad7b3f9b9aeb.zip
Use linenoise to add simple editing and history to the Android shell.
The linenoise library is from http://github.com/antirez/linenoise This patch also disables command-line editing and history from adb. The adb implementation was shadowing the Android shell's implementation. The adb implementation was also shadowing the editing and history implementation in alternative shells such as BusyBox's ash. Change-Id: I7ebd4cb391d0ce966c0ce0e707d80ecd659f9079
Diffstat (limited to 'sh/input.c')
-rw-r--r--sh/input.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/sh/input.c b/sh/input.c
index a81fd7b18..9377bd025 100644
--- a/sh/input.c
+++ b/sh/input.c
@@ -64,6 +64,10 @@ __RCSID("$NetBSD: input.c,v 1.39 2003/08/07 09:05:32 agc Exp $");
#include "parser.h"
#include "myhistedit.h"
+#ifdef WITH_LINENOISE
+#include "linenoise.h"
+#endif
+
#define EOF_NLEFT -99 /* value of parsenleft when EOF pushed back */
MKINIT
@@ -203,6 +207,45 @@ retry:
} else
#endif
+#ifdef WITH_LINENOISE
+ if (parsefile->fd == 0) {
+ static char *rl_start;
+ static const char *rl_cp;
+ static int el_len;
+
+ if (rl_cp == NULL) {
+ rl_cp = rl_start = linenoise(getprompt(""));
+ if (rl_cp != NULL) {
+ el_len = strlen(rl_start);
+ if (el_len != 0) {
+ /* Add non-blank lines to history. */
+ linenoiseHistoryAdd(rl_start);
+ }
+ out2str("\r\n");
+ /* Client expects a newline at end of input, doesn't expect null */
+ rl_start[el_len++] = '\n';
+ }
+ }
+ if (rl_cp == NULL)
+ nr = 0;
+ else {
+ nr = el_len;
+ if (nr > BUFSIZ - 8)
+ nr = BUFSIZ - 8;
+ memcpy(buf, rl_cp, nr);
+ if (nr != el_len) {
+ el_len -= nr;
+ rl_cp += nr;
+ } else {
+ rl_cp = 0;
+ if (rl_start != NULL) {
+ free(rl_start);
+ rl_start = NULL;
+ }
+ }
+ }
+ } else
+#endif
nr = read(parsefile->fd, buf, BUFSIZ - 8);