Skip to content

Commit f230d66

Browse files
Fix ANSI replay parser edge cases
Assisted-By: devx/b840c1e6-d979-473d-9216-a53477380bf1
1 parent 41975df commit f230d66

23 files changed

Lines changed: 839 additions & 111 deletions

lib/cli/ui/ansi.rb

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -51,31 +51,19 @@ def strip_codes(str)
5151
str.gsub(Regexp.union(CSI_SEQUENCE, OSC_SEQUENCE, /\r/), '')
5252
end
5353

54-
# Replays the viewport-independent cursor controls in a captured
55-
# terminal stream, so repaints (spinners, progress bars) collapse
56-
# onto their final state instead of accumulating one frame per tick.
57-
#
58-
# Where +strip_codes+ deletes control sequences, this applies them.
59-
# Operations that assume a viewport -- screen-relative positioning,
60-
# display erasure, wrapping -- are ignored: a capture does not
61-
# record scrolling, so screen coordinates have no buffer row to map
62-
# onto. Alternate-screen content (a full-screen prompt, a pager) is
63-
# discarded on exit, as a terminal discards it. Commands a repaint
64-
# has no use for, from character editing to charset translation,
65-
# are dropped without effect. The stream is decoded as UTF-8
66-
# whatever its tagged encoding, replacing bytes that don't decode.
67-
# Columns hold one grapheme cluster each, using Unicode terminal
68-
# widths so wide glyphs keep their two columns when overwritten.
69-
# Trailing whitespace on every line is trimmed: a terminal renders
70-
# nothing there.
54+
# Returns the text left by applying terminal repaint controls in a
55+
# captured stream. Presentation controls are dropped and malformed
56+
# input is replaced while decoding the result as UTF-8.
7157
#
7258
# ==== Attributes
7359
#
7460
# - +str+ - The captured terminal stream to replay
61+
# - +diagnostics+ - Optional hash populated when replay encounters
62+
# terminal operations it cannot model
7563
#
76-
#: (String str) -> String
77-
def replay(str)
78-
Replay.render(str)
64+
#: (String str, ?diagnostics: Hash[Symbol, bool]?) -> String
65+
def replay(str, diagnostics: nil)
66+
Replay.render(str, diagnostics: diagnostics)
7967
end
8068

8169
# Returns an ANSI control sequence

0 commit comments

Comments
 (0)