aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2020-10-13 20:30:03 +0200
committerPřemysl Eric Janouch <p@janouch.name>2020-10-13 20:30:33 +0200
commitc87869bef7553199a874a7af304d2a4b13f0f689 (patch)
tree2a42265fee449b79d62395c48ffc51f1acbcda5f
parentfcf65f837795f8251aa9bb6249065464141e7cdd (diff)
downloadjson-rpc-shell-c87869bef7553199a874a7af304d2a4b13f0f689.tar.gz
json-rpc-shell-c87869bef7553199a874a7af304d2a4b13f0f689.tar.xz
json-rpc-shell-c87869bef7553199a874a7af304d2a4b13f0f689.zip
Cleanup
Prevent the last fuck-up from happening again.
-rw-r--r--json-rpc-shell.c31
1 files changed, 17 insertions, 14 deletions
diff --git a/json-rpc-shell.c b/json-rpc-shell.c
index 2ddb95c..adcf310 100644
--- a/json-rpc-shell.c
+++ b/json-rpc-shell.c
@@ -664,6 +664,14 @@ input_el_install_prompt (struct input_el *self)
static unsigned char input_el_on_complete (EditLine *editline, int key);
static void
+input_el_addbind (EditLine *editline, const char *name, const char *desc,
+ unsigned char (*function) (EditLine *, int), const char *binding)
+{
+ el_set (editline, EL_ADDFN, name, desc, function);
+ el_set (editline, EL_BIND, binding, name, NULL);
+}
+
+static void
input_el_start (struct input *input, const char *program_name)
{
struct input_el *self = (struct input_el *) input;
@@ -681,20 +689,15 @@ input_el_start (struct input *input, const char *program_name)
el_set (self->editline, EL_BIND, "^u", "vi-kill-line-prev", NULL);
// It's probably better to handle these ourselves
- el_set (self->editline, EL_ADDFN,
- "send-line", "Send line", input_el_on_return);
- el_set (self->editline, EL_BIND, "\n", "send-line", NULL);
- el_set (self->editline, EL_ADDFN,
- "run-editor", "Run editor to edit line", input_el_on_run_editor);
- el_set (self->editline, EL_BIND, "M-e", "run-editor", NULL);
-
- el_set (self->editline, EL_ADDFN,
- "complete", "Complete word", input_el_on_complete);
- el_set (self->editline, EL_BIND, "\t", "complete", NULL);
-
- el_set (self->editline, EL_ADDFN,
- "newline-insert", "Insert a newline", input_el_on_newline_insert);
- el_set (self->editline, EL_BIND, "M-\n", "newline-insert", NULL);
+ input_el_addbind (self->editline, "send-line", "Send line",
+ input_el_on_return, "\n");
+ input_el_addbind (self->editline, "run-editor", "Run editor to edit line",
+ input_el_on_run_editor, "M-e");
+
+ input_el_addbind (self->editline, "complete", "Complete word",
+ input_el_on_complete, "\t");
+ input_el_addbind (self->editline, "newline-insert", "Insert a newline",
+ input_el_on_newline_insert, "M-\n");
// Source the user's defaults file
el_source (self->editline, NULL);