From c0d0b2633dfaed07fd03befd1272a4e409fda9be Mon Sep 17 00:00:00 2001 From: Luxferre Date: Sat, 3 Oct 2026 19:18:12 +0300 Subject: [PATCH] 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. --- main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.c b/main.c index 9e633ca..030ddf5 100644 --- a/main.c +++ b/main.c @@ -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 : ""); fflush(stdout); 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(IN) { IN = 0; free(ln); continue; } ac = ln;