summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2021-10-30 08:28:05 +0200
committerPřemysl Eric Janouch <p@janouch.name>2021-10-30 08:29:16 +0200
commitdf4ca745807852be4e7588a41fe311c12f41ddb4 (patch)
treeb45c91333c38012c641d6e3c8b54fb22e894dc16
parent9e297244a4505fcb25e4d4896a154de77fbe6072 (diff)
downloadxK-df4ca745807852be4e7588a41fe311c12f41ddb4.tar.gz
xK-df4ca745807852be4e7588a41fe311c12f41ddb4.tar.xz
xK-df4ca745807852be4e7588a41fe311c12f41ddb4.zip
xC: make libedit autocomplete less miserable
Omitting even this hack was a huge hit to overall usability.
-rw-r--r--xC.c26
1 files changed, 20 insertions, 6 deletions
diff --git a/xC.c b/xC.c
index 37783b7..1f4ff0f 100644
--- a/xC.c
+++ b/xC.c
@@ -13698,19 +13698,33 @@ on_editline_complete (EditLine *editline, int key)
// Insert the best match instead
el_insertstr (editline, completions[0]);
+
+ // I'm not sure if Readline's menu-complete can at all be implemented
+ // with Editline--we have no way of detecting what the last executed handler
+ // was. Employ the formatter's wrapping feature to spew all options.
bool only_match = !completions[1];
+ if (!only_match)
+ {
+ CALL (ctx->input, hide);
+ redraw_screen (ctx);
+
+ struct formatter f = formatter_make (ctx, NULL);
+ for (char **p = completions; *++p; )
+ formatter_add (&f, " #l", *p);
+ formatter_add (&f, "\n");
+ formatter_flush (&f, stdout, 0);
+ formatter_free (&f);
+
+ CALL (ctx->input, show);
+ }
+
for (char **p = completions; *p; p++)
free (*p);
free (completions);
-
- // I'm not sure if Readline's menu-complete can at all be implemented
- // with Editline. Spamming the terminal with possible completions
- // probably isn't what the user wants and we have no way of detecting
- // what the last executed handler was.
if (!only_match)
return CC_REFRESH_BEEP;
- // But if there actually is just one match, finish the word
+ // If there actually is just one match, finish the word
el_insertstr (editline, " ");
return CC_REFRESH;
}