From 38c23d0d38f74e82f96c4e385395a31e651b0f5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Eric=20Janouch?=
Date: Sat, 31 Oct 2020 15:15:08 +0100 Subject: [PATCH] degesch: fix fancy-prompt.lua with libedit Partly by unifying the interface for prompt hooks to match GNU Readline. --- degesch.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/degesch.c b/degesch.c index e695752..ee3e455 100644 --- a/degesch.c +++ b/degesch.c @@ -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);