fix readline redisplay issue with a prompt containing terminal escape sequences that needs to change (e.g., to show the vi editing mode) after a paste that leaves the cursor in column 0; fix readline display overflow with a prompt that contains more than 256 wrapped lines

This commit is contained in:
Chet Ramey
2026-07-01 11:04:36 -04:00
parent 76037847c3
commit 0e16a4e4b1
6 changed files with 215 additions and 1224 deletions
+7 -2
View File
@@ -1024,6 +1024,7 @@ rl_redisplay (void)
while (local_prompt_newlines[newlines+1] != -1)
{
temp = local_prompt_newlines[newlines+1];
CHECK_INV_LBREAKS ();
inv_lbreaks[++newlines] = temp;
}
@@ -2218,6 +2219,9 @@ update_line (char *old, char *old_face, char *new, char *new_face, int current_l
can't directly check it) is still on the visible line because we
haven't overwritten it yet. We guess that there aren't any invisible
characters in any of the prompts we put in with rl_message */
/* This is wrong if the prompt is switching between two variants, both
with invisible characters (e.g., when using mode strings with terminal
escape sequences). */
else if (current_line == 0 && local_prompt && new[0] == local_prompt[0] &&
(memcmp (new, local_prompt, local_prompt_len) == 0) &&
(memcmp (old, local_prompt, local_prompt_len) != 0))
@@ -2261,11 +2265,12 @@ update_line (char *old, char *old_face, char *new, char *new_face, int current_l
od = ofd - old; /* index of first difference in visible line */
nd = nfd - new; /* nd, od are buffer indexes */
if (current_line == 0 && !_rl_horizontal_scroll_mode &&
_rl_term_cr && lendiff > prompt_visible_length && _rl_last_c_pos > 0 &&
_rl_term_cr && lendiff > prompt_visible_length && _rl_last_c_pos >= 0 &&
(((od > 0 || nd > 0) && (od <= prompt_last_invisible || nd <= prompt_last_invisible)) ||
((od >= lendiff) && _rl_last_c_pos < PROMPT_ENDING_INDEX)))
{
_rl_cr ();
if (_rl_last_c_pos > 0)
_rl_cr ();
if (modmark)
_rl_output_some_chars ("*", 1);
_rl_output_some_chars (local_prompt, lendiff);