From 444f97b35757f31890a3a62b0b2caa84d750f2a1 Mon Sep 17 00:00:00 2001 From: Přemysl Eric Janouch Date: Wed, 2 Sep 2020 19:35:38 +0200 Subject: degesch: work around a libedit attribute issue --- degesch.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/degesch.c b/degesch.c index 0a24d10..b1f9611 100644 --- a/degesch.c +++ b/degesch.c @@ -1089,7 +1089,6 @@ input_el_show (void *input) return; input_el__restore (self); - // XXX: the ignore doesn't quite work, see https://gnats.netbsd.org/47539 el_set (self->editline, EL_PROMPT_ESC, input_el__make_prompt, INPUT_START_IGNORE); input_el__redisplay (self); @@ -5939,18 +5938,32 @@ on_refresh_prompt (struct app_context *ctx) struct str prompt = str_make (); make_prompt (ctx, &prompt); + + // libedit has a weird bug where it misapplies ignores when they're not + // followed by anything else, so let's try to move a trailing space, + // which will at least fix the default prompt. + const char *attributed_suffix = ""; +#ifdef HAVE_EDITLINE + if (have_attributes && prompt.len && prompt.str[prompt.len - 1] == ' ') + { + prompt.str[--prompt.len] = 0; + attributed_suffix = " "; + } +#endif // HAVE_EDITLINE + char *localized = iconv_xstrdup (ctx->term_from_utf8, prompt.str, -1, NULL); str_free (&prompt); if (have_attributes) { // XXX: to be completely correct, we should use tputs, but we cannot - input_maybe_set_prompt (ctx->input, xstrdup_printf ("%c%s%c%s%c%s%c", + input_maybe_set_prompt (ctx->input, xstrdup_printf ("%c%s%c%s%c%s%c%s", INPUT_START_IGNORE, ctx->attrs[ATTR_PROMPT], INPUT_END_IGNORE, localized, INPUT_START_IGNORE, ctx->attrs[ATTR_RESET], - INPUT_END_IGNORE)); + INPUT_END_IGNORE, + attributed_suffix)); free (localized); } else -- cgit v1.2.3-70-g09d2