fix wrapping of input lines that overflow the terminal width

The prompt passed to readline() contained raw ANSI SGR sequences
("\e[1;37m" and "\e[0m") with no marker for readline to exclude them
from its column accounting, so readline counted those 9 bytes as
printable columns. While typing this was invisible, but once the line
wrapped, readline's display model carried one extra (phantom) row. On
accept, _rl_update_final() then took its "remove the final xterm
line-wrap flag" branch, moving the cursor up one row and repainting the
final character over the end of the previous row. The multi-line
continuation loop made it obvious: the "... " prompt was printed on top
of the wrapped tail and the continued line landed one row too high.

Wrapping the escape sequences in readline's \001 / \002 non-printing
markers makes their width 0, which removes the phantom row. The joined
text was already correct; only the rendering was wrong.

Verified at 40 columns with a 67 character line and at 80 columns with
a 147 character line, both the lengths that triggered the corruption.
This commit is contained in:
Luxferre
2026-10-03 19:18:12 +03:00
parent 9513780a02
commit c0d0b2633d
+1 -1
View File
@@ -378,7 +378,7 @@ int main(int argc, char **argv) {
printf("%sAgent Solo ready%s%s [%s | %s | %s]%s\n", CLR ? BLD : "", CLR ? OF : "", CLR ? GRY : "", EP, MOD, RSN, CLR ? OF : ""); printf("%sAgent Solo ready%s%s [%s | %s | %s]%s\n", CLR ? BLD : "", CLR ? OF : "", CLR ? GRY : "", EP, MOD, RSN, CLR ? OF : "");
fflush(stdout); fflush(stdout);
while(!QUIT) { while(!QUIT) {
snprintf(pb, sizeof pb, "%s> %s", CLR ? BLD : "", CLR ? OF : ""); snprintf(pb, sizeof pb, "\001%s\002> \001%s\002", CLR ? BLD : "", CLR ? OF : "");
if(!(ln = readline(pb))) { puts(""); break; } if(!(ln = readline(pb))) { puts(""); break; }
if(IN) { IN = 0; free(ln); continue; } if(IN) { IN = 0; free(ln); continue; }
ac = ln; ac = ln;