aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2020-10-31 15:15:08 +0100
committerPřemysl Eric Janouch <p@janouch.name>2020-10-31 16:04:30 +0100
commit38c23d0d38f74e82f96c4e385395a31e651b0f5f (patch)
tree74c82189941c1df6482c61fe9ddd33ecfc7e4d28
parent439af8884c5f75d636327bf6b974b510e899d252 (diff)
downloadxK-38c23d0d38f74e82f96c4e385395a31e651b0f5f.tar.gz
xK-38c23d0d38f74e82f96c4e385395a31e651b0f5f.tar.xz
xK-38c23d0d38f74e82f96c4e385395a31e651b0f5f.zip
degesch: fix fancy-prompt.lua with libedit
Partly by unifying the interface for prompt hooks to match GNU Readline.
-rw-r--r--degesch.c14
1 files changed, 14 insertions, 0 deletions
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);