degesch: work around a libedit attribute issue

This commit is contained in:
Přemysl Eric Janouch 2020-09-02 19:35:38 +02:00
parent ed7130a664
commit 444f97b357
Signed by: p
GPG Key ID: A0420B94F92B9493
1 changed files with 16 additions and 3 deletions

View File

@ -1089,7 +1089,6 @@ input_el_show (void *input)
return; return;
input_el__restore (self); input_el__restore (self);
// XXX: the ignore doesn't quite work, see https://gnats.netbsd.org/47539
el_set (self->editline, el_set (self->editline,
EL_PROMPT_ESC, input_el__make_prompt, INPUT_START_IGNORE); EL_PROMPT_ESC, input_el__make_prompt, INPUT_START_IGNORE);
input_el__redisplay (self); input_el__redisplay (self);
@ -5939,18 +5938,32 @@ on_refresh_prompt (struct app_context *ctx)
struct str prompt = str_make (); struct str prompt = str_make ();
make_prompt (ctx, &prompt); 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); char *localized = iconv_xstrdup (ctx->term_from_utf8, prompt.str, -1, NULL);
str_free (&prompt); str_free (&prompt);
if (have_attributes) if (have_attributes)
{ {
// XXX: to be completely correct, we should use tputs, but we cannot // 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_START_IGNORE, ctx->attrs[ATTR_PROMPT],
INPUT_END_IGNORE, INPUT_END_IGNORE,
localized, localized,
INPUT_START_IGNORE, ctx->attrs[ATTR_RESET], INPUT_START_IGNORE, ctx->attrs[ATTR_RESET],
INPUT_END_IGNORE)); INPUT_END_IGNORE,
attributed_suffix));
free (localized); free (localized);
} }
else else