xC: make libedit autocomplete less miserable

Omitting even this hack was a huge hit to overall usability.
This commit is contained in:
Přemysl Eric Janouch 2021-10-30 08:28:05 +02:00
parent 9e297244a4
commit df4ca74580
Signed by: p
GPG Key ID: A0420B94F92B9493
1 changed files with 20 additions and 6 deletions

26
xC.c
View File

@ -13698,19 +13698,33 @@ on_editline_complete (EditLine *editline, int key)
// Insert the best match instead // Insert the best match instead
el_insertstr (editline, completions[0]); 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]; 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++) for (char **p = completions; *p; p++)
free (*p); free (*p);
free (completions); 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) if (!only_match)
return CC_REFRESH_BEEP; 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, " "); el_insertstr (editline, " ");
return CC_REFRESH; return CC_REFRESH;
} }