summaryrefslogtreecommitdiffhomepage
path: root/tests/linux
diff options
context:
space:
mode:
authorSean Kurtz <seankurtz75@gmail.com>2026-11-25 20:30:22 -0600
committerSean Kurtz <seankurtz75@gmail.com>2026-11-25 20:30:22 -0600
commitdeb0ed011fe2cfc7058facb3f63b7feaeb8d4a8e (patch)
treea05698851d28feb88d9bcf95a3530792b719b16b /tests/linux
parent456955dc33f24b1e9857bdc3c11788a2358e954c (diff)
downloadzash-deb0ed011fe2cfc7058facb3f63b7feaeb8d4a8e.tar.gz
interactive: a prompt's width counts columns, not bytes
The built-in editor skipped `ESC [ ...` sequences when working out where the prompt ends. Colour and titles are not all CSI: an OSC title or hyperlink runs to BEL or `ESC \`, DCS runs the same way, and `tput sgr0` is the three-byte `ESC ( B` before `ESC [ m`. A prompt built with `$(tput ...)` was measured wrong, which costs the cursor position and with it the wrapped-line arithmetic. `esc_seq_len()` in interact.c now walks what a terminal understands, and edit_builtin.c uses it. The libedit build shares the walk: it brackets control runs for `EL_PROMPT_ESC`, and adds the space libedit needs when a prompt ends in one, since libedit attaches a literal run to the character after it. bench/editor.py measures the two costs run.sh cannot see, start to first prompt and per-key echo, on a pty; bench/README.md has the table. The release, z/OS and fuzz builds move to -O3 while the sanitizer and coverage builds stay low: inlined frames make their reports harder to read than the few percent they would gain.
Diffstat (limited to 'tests/linux')
-rw-r--r--tests/linux/i-prompt-esc.exp4
-rw-r--r--tests/linux/i-prompt-esc.sh21
2 files changed, 25 insertions, 0 deletions
diff --git a/tests/linux/i-prompt-esc.exp b/tests/linux/i-prompt-esc.exp
new file mode 100644
index 0000000..0d6e3de
--- /dev/null
+++ b/tests/linux/i-prompt-esc.exp
@@ -0,0 +1,4 @@
+$ 32mP\e[0m> '
+]0;t(BP> Xabcdefghijklmn
+]0;t(BP> exit
+[status 0]
diff --git a/tests/linux/i-prompt-esc.sh b/tests/linux/i-prompt-esc.sh
new file mode 100644
index 0000000..18efd07
--- /dev/null
+++ b/tests/linux/i-prompt-esc.sh
@@ -0,0 +1,21 @@
+# Interactive: a prompt carrying sequences that are not just SGR.
+#
+# A terminal title (OSC, ended by BEL) and the charset reset plus colour
+# that `tput sgr0` writes (`ESC ( B ESC [ m`) both come from a terminal's
+# terminfo entry, and a prompt copied from elsewhere is full of them.
+# None of them takes a column, so the line scrolls where a plain prompt
+# of the same width would: a width rule that knows only `ESC [ ... m`
+# counts the title and the `(B` as text, keeps 7 columns too few, and the
+# redraw after ^A shows a shorter window than this expectation.
+command -v python3 >/dev/null 2>&1 || exit 77
+python3 "$TESTS/tools/ptydrive.py" -c 16 "$TSH" <<'END'
+send PS1='\\e]0;t\x07\\e(B\\e[1;32mP\\e[0m> '\r
+expect P>
+send abcdefghijklmn
+send \x01
+send X
+expect Xabcdefghijk
+send \x03
+expect P>
+send exit\r
+END