code comments changes

This commit is contained in:
Vaclav Tvrdik
2026-09-10 10:07:12 +02:00
parent d2b763a95a
commit 2a8fffb9c6
13 changed files with 123 additions and 208 deletions

View File

@@ -83,7 +83,7 @@ assert terminal.screen.theme_is_dark is True
# without mode 2031 the app is not interrupted
assert recorder.written == "", repr(recorder.written)
# with it, the dark/light report is sent so the agent can restyle itself
# with it, the dark/light report is sent so the app can restyle itself
stream.feed("\x1b[?2031h")
recorder.written = ""
terminal.apply_scheme()

View File

@@ -24,7 +24,7 @@ def feed(stream, data, char_by_char=False):
def run_case(char_by_char):
tag = "char-by-char" if char_by_char else "chunked"
# DA1 answered (Claude Code's untimed sentinel)
# DA1 answered; apps can wait on it with no timeout
proc, screen, stream = make()
feed(stream, "\x1b[c", char_by_char)
assert proc.written == "\x1b[?62;22c", (tag, proc.written)
@@ -34,7 +34,7 @@ def run_case(char_by_char):
feed(stream, "\x1b[5;10H\x1b[6n\x1b[?6n", char_by_char)
assert proc.written == "\x1b[5;10R\x1b[?5;10R", (tag, proc.written)
# XTVERSION then DECRQM 2026 (the Claude Code probe sequence)
# XTVERSION then DECRQM 2026, the sync-output probe sequence
proc, screen, stream = make()
feed(stream, "\x1b[>0q\x1b[c\x1b[?2026$p\x1b[c", char_by_char)
assert proc.written == (
@@ -54,8 +54,8 @@ def run_case(char_by_char):
# and nothing leaked to the screen
assert screen.buffer[0][0].data == " ", (tag, screen.buffer[0][0])
# modifyOtherKeys: the level is tracked (pi enables it and reads shift+enter
# no other way), and the sequence must not corrupt SGR state
# modifyOtherKeys: the level is tracked, and the sequence must not corrupt
# SGR state
proc, screen, stream = make()
assert screen.modify_other_keys == 0, tag
feed(stream, "\x1b[>4;2mhello", char_by_char)
@@ -211,8 +211,8 @@ def run_resize_cases():
feed(stream, "\x1b[?1049l", False)
assert max(screen.buffer[0]) < 8, sorted(screen.buffer[0])
# a shrink clamps the cursor (pyte does it via restore_cursor); without
# the clamp draw() writes to rows above or below the screen
# a shrink clamps the cursor; without the clamp draw() writes to rows
# above or below the screen
proc, screen, stream = make(10, 8)
feed(stream, "\r\n".join("line{}".format(i) for i in range(8)), False)
feed(stream, "\x1b[1;1H", False) # full screen, cursor at home
@@ -239,8 +239,8 @@ def run_resize_cases():
def run_private_csi_cases():
"""No private CSI may raise: an exception here used to kill the renderer
thread and freeze the tab. aerc probes XTSMGRAPHICS (ESC[?2;1;0S)."""
"""No private CSI may raise: an exception here kills the renderer thread
and freezes the tab. aerc probes XTSMGRAPHICS (ESC[?2;1;0S)."""
for final in "ABCDEFGHJKLMPSTXZbcdfghlmnqrstu@":
proc, screen, stream = make()
stream.feed("\x1b[?2;1;0" + final) # multi-parameter private CSI
@@ -269,9 +269,9 @@ def run_private_csi_cases():
def run_decscnm_cases():
"""A DECSCNM flash (vim's visual bell) must not outlive itself.
pyte points every line at the blank cell from inside set/reset_mode, so a
line kept a reverse default and painted the columns the app never wrote —
vim skips indentation with cursor-forward — as white blocks.
The lines point at the blank cell, so one keeping a reverse default paints
the columns the app never wrote — vim skips indentation with cursor-forward
— as white blocks.
"""
from vterm.render import segment_buffer_line
@@ -327,7 +327,7 @@ def run_fast_path_cases():
return (rows, c.x, c.y, c.attrs, set(screen.mode), screen.title)
def parser_only(blob):
"""The blob through the coroutine parser alone: pyte's original feed."""
"""The blob through the coroutine parser alone, bypassing the fast path."""
proc, screen, stream = make(columns=30, lines=8)
import pyte
pyte.Stream.feed(stream, blob)
@@ -407,7 +407,7 @@ def run_clear_cases():
assert len(screen.history) > 0, "history suppressed for too long"
# ED 3 is app-driven: it clears scrollback and fires the clear callback,
# but (as in xterm, unlike pyte) leaves the visible screen alone
# but (as in xterm) leaves the visible screen alone
cleared = []
proc = FakeProcess()
screen = VtScreen(10, 4, process=proc, clear_callback=lambda: cleared.append(1))
@@ -418,8 +418,8 @@ def run_clear_cases():
assert len(screen.history) == 0 and cleared, (len(screen.history), cleared)
assert screen.buffer[0][0].data == "a", screen.buffer[0][0]
# with erase_scrollback off, ED 3 is a no-op: agents repaint with it and
# would take the history and the view with them
# with erase_scrollback off, ED 3 is a no-op: an app repainting with it
# would take the history and the view with it
cleared = []
proc = FakeProcess()
screen = VtScreen(10, 4, process=proc, erase_scrollback=False,

View File

@@ -54,8 +54,8 @@ for char in string.ascii_letters + string.digits + string.punctuation:
assert get_key_code(key="space") == " ", "space must send a space"
# legacy encodings by default; while the app has modifyOtherKeys on, the keys
# whose modified form is ambiguous take the CSI 27 form instead. pi reads a
# bare ESC CR as alt+enter and submits on it
# whose modified form is ambiguous take the CSI 27 form instead. a bare ESC CR
# reads as alt+enter
assert get_key_code(key="enter", shift=True) == "\x1b\r"
assert get_key_code(key="enter", shift=True, modify_other_keys=2) == "\x1b[27;2;13~"
assert get_key_code(key="space", ctrl=True, modify_other_keys=2) == "\x1b[27;5;32~"

View File

@@ -226,8 +226,8 @@ assert len(selection) == 1 and selection[0].empty(), \
print("selection tests passed (user selection survives renders, caret still tracked)")
# an app that hides the cursor (pi hides it for good) still needs the caret:
# sublime drops a space keypress in a view that has no caret at all
# an app that hides the cursor still needs the caret: sublime drops a space
# keypress in a view that has no caret at all
selection.clear()
stream.feed("\x1b[?25l")
focus_cursor(terminal.view, None, terminal)
@@ -326,7 +326,7 @@ command.run(None)
kept = [(r.begin(), r.end()) for r in terminal.view.sel()]
assert any(b != e for b, e in kept), "user selection was dropped: {}".format(kept)
# pyte's dirty is a repaint hint: rows whose content did not change must not
# the dirty set is a repaint hint: rows whose content did not change must not
# be rewritten (each rewrite is a cross-process call and an on_modified)
rewritten = []
_replace = terminal.view.replace
@@ -523,8 +523,8 @@ print("view scroll tests passed (a screen or a row per press, clamped to the anc
# shift+enter through the whole keypress path: ESC CR by default, and the CSI 27
# form once the app turned modifyOtherKeys on. pi enables it (its kitty probe
# gets no flags from us) and reads a bare ESC CR as alt+enter, which submits
# form once the app turned modifyOtherKeys on, which it reaches for because a
# bare ESC CR reads as alt+enter
press(key="enter", shift=True)
assert terminal.process.written == "\x1b\r", repr(terminal.process.written)
stream.feed("\x1b[>4;2m")