degesch: fix fancy-prompt.lua with libedit

Partly by unifying the interface for prompt hooks to match GNU Readline.
This commit is contained in:
Přemysl Eric Janouch 2020-10-31 15:15:08 +01:00
parent 439af8884c
commit 38c23d0d38
Signed by: p
GPG Key ID: A0420B94F92B9493
1 changed files with 14 additions and 0 deletions

View File

@ -6028,6 +6028,14 @@ make_prompt (struct app_context *ctx, struct str *output)
static void
input_maybe_set_prompt (struct input *self, char *new_prompt)
{
// Fix libedit's expectations to see a non-control character following
// the end mark (see prompt.c and literal.c) by cleaning this up
for (char *p = new_prompt; *p; )
if (p[0] == INPUT_END_IGNORE && p[1] == INPUT_START_IGNORE)
memmove (p, p + 2, strlen (p + 2) + 1);
else
p++;
// Redisplay can be an expensive operation
const char *prompt = CALL (self, get_prompt);
if (prompt && !strcmp (new_prompt, prompt))
@ -6055,6 +6063,12 @@ on_refresh_prompt (struct app_context *ctx)
prompt.str[--prompt.len] = 0;
attributed_suffix = " ";
}
// Also enable a uniform interface for prompt hooks by assuming it uses
// GNU Readline escapes: turn this into libedit's almost-flip-flop
for (size_t i = 0; i < prompt.len; i++)
if (prompt.str[i] == '\x01' || prompt.str[i] == '\x02')
prompt.str[i] = INPUT_START_IGNORE /* == INPUT_END_IGNORE */;
#endif // HAVE_EDITLINE
char *localized = iconv_xstrdup (ctx->term_from_utf8, prompt.str, -1, NULL);