aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2020-09-02 01:07:31 +0200
committerPřemysl Eric Janouch <p@janouch.name>2020-09-02 01:08:09 +0200
commitb7b1198be76e46c6e151a4092ba101c9c0a33693 (patch)
tree391df59ae44c9fe23868cb13b2e67a8cfc03f8a2
parent633f7007d1e9cf6492560ed4e644f6c4d92747f8 (diff)
downloadjson-rpc-shell-b7b1198be76e46c6e151a4092ba101c9c0a33693.tar.gz
json-rpc-shell-b7b1198be76e46c6e151a4092ba101c9c0a33693.tar.xz
json-rpc-shell-b7b1198be76e46c6e151a4092ba101c9c0a33693.zip
Fix libedit a bit more and discourage from using it
-rw-r--r--README.adoc3
-rw-r--r--json-rpc-shell.c14
2 files changed, 15 insertions, 2 deletions
diff --git a/README.adoc b/README.adoc
index 9c4fec4..646c93a 100644
--- a/README.adoc
+++ b/README.adoc
@@ -47,6 +47,9 @@ Build dependencies: CMake, pkg-config, help2man,
Runtime dependencies: libev, Jansson, cURL, openssl,
readline or libedit >= 2013-07-12,
+Avoid libedit if you can, in general it works but at the moment history is
+acting up and I have no clue about fixing it.
+
$ git clone --recursive https://git.janouch.name/p/json-rpc-shell.git
$ mkdir json-rpc-shell/build
$ cd json-rpc-shell/build
diff --git a/json-rpc-shell.c b/json-rpc-shell.c
index 8f74a06..8f1e147 100644
--- a/json-rpc-shell.c
+++ b/json-rpc-shell.c
@@ -619,7 +619,6 @@ input_el_on_run_editor (EditLine *editline, int key)
static void
input_el_install_prompt (struct input_el *self)
{
- // XXX: the ignore doesn't quite work, see https://gnats.netbsd.org/47539
el_set (self->editline, EL_PROMPT_ESC,
input_el_make_prompt, INPUT_START_IGNORE);
}
@@ -634,7 +633,7 @@ input_el_start (struct input *input, const char *program_name)
el_set (self->editline, EL_CLIENTDATA, self);
input_el_install_prompt (self);
el_set (self->editline, EL_SIGNAL, false);
- el_set (self->editline, EL_UNBUFFERED, true);
+ el_set (self->editline, EL_UNBUFFERED, isatty (fileno (stdin)));
el_set (self->editline, EL_EDITOR, "emacs");
el_wset (self->editline, EL_HIST, history_w, self->history);
@@ -834,6 +833,17 @@ input_el_on_tty_readable (struct input *input)
int count = 0;
const wchar_t *buf = el_wgets (self->editline, &count);
+ // Editline works in a funny NO_TTY mode when the input is not a tty,
+ // we cannot use EL_UNBUFFERED and expect sane results then
+ int unbuffered = 0;
+ if (!el_get (self->editline, EL_UNBUFFERED, &unbuffered) && !unbuffered)
+ {
+ char *entered_line = buf ? input_el_wcstombs (buf) : NULL;
+ self->super.on_input (entered_line, self->super.user_data);
+ free (entered_line);
+ return;
+ }
+
// Process data from our newline handler (async-friendly handling)
if (self->entered_line)
{