aboutsummaryrefslogtreecommitdiff
path: root/json-rpc-shell.c
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 /json-rpc-shell.c
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
Diffstat (limited to 'json-rpc-shell.c')
-rw-r--r--json-rpc-shell.c14
1 files changed, 12 insertions, 2 deletions
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)
{