perf(highlight): precompute SGR at compile, sorted span claiming, stream ESC-free fast path
- compileRules precomputes the full SGR open sequence per rule and per band; wrap() is now pure concatenation, bandOpen() a table lookup (output bytes unchanged, bg keeps its unvalidated white-fallback) - claim() replaces the linear overlaps() scan: claimed spans stay sorted by start, O(1) append on the common left-to-right sweep plus one binary search otherwise (match-dense 200KB payload: -19% one-shot, -56% streamed) - HighlightStream: bufferHasEsc flag skips the O(buffer) escape rescans when neither the held text nor the chunk contains ESC, fixing quadratic rescan on escape-free floods (plain 200KB streamed: -54%) - applyHighlights tracks the consumed match budget incrementally instead of two budgets.reduce() passes per text token - ESCAPE_RE now covers DCS/APC/PM/SOS (BEL or ST terminated) and single-char Fe escapes (DECSC/DECRC/NEL/RI/RIS, orphan ST); isIncompleteEscape holds cut tails of the new families; split-smoke exercises every cut point through them
This commit is contained in:
1 parent
4e5377f49c
commit
462da60977
3 files changed
+220
-57
No files matched your search
@@ -7,12 +7,24 @@ import { DEFAULT_HIGHLIGHT_RULES } from '../src/shared/settings.ts'
|
||||
|
||||
const rules = compileRules(DEFAULT_HIGHLIGHT_RULES)
|
||||
|
||||
// kimi-like: truecolor SGR, OSC title, box drawing, per-line repaints
|
||||
// kimi-like: truecolor SGR, OSC title, box drawing, per-line repaints.
|
||||
// The tail line exercises the string-terminated families (DCS/sixel, APC/kitty
|
||||
// graphics, PM, SOS), a BEL-terminated DCS, and DECSC/DECRC (`\x1b7`/`\x1b8`)
|
||||
// so every cut point through them is checked against the reference.
|
||||
const banner =
|
||||
'\x1b]0;kimi — session\x07' +
|
||||
'\x1b[38;2;79;168;255m╭───────╮\x1b[0m\r\n' +
|
||||
'\x1b[38;2;136;136;136mWelcome to Kimi Code!\x1b[0m \x1b[38;2;79;168;255m│\x1b[0m send /help\r\n' +
|
||||
'\x1b[38;2;224;224;224mModel: MiniMax-M3 0.41.038 ERROR 99% https://example.com/x\x1b[0m\r\n'
|
||||
'\x1b[38;2;224;224;224mModel: MiniMax-M3 0.41.038 ERROR 99% https://example.com/x\x1b[0m\r\n' +
|
||||
'\x1b7' +
|
||||
'\x1b[38;2;224;224;224mERROR 85% exit code 1\x1b[0m' +
|
||||
'\x1bP0;1;0q#0;2;0;0;0~-..\x1b\\' +
|
||||
'\x1bP1;2|9/9\x07' +
|
||||
'\x1b_Gf=32,s=10,v=10,m=1\x1b\\' +
|
||||
'\x1b^pm-note\x1b\\' +
|
||||
'\x1bXsos-frame\x1b\\' +
|
||||
'\x1b[38;2;136;136;136mdone \u2713\x1b[0m' +
|
||||
'\x1b8\r\n'
|
||||
|
||||
const reference = applyHighlights(banner, rules)
|
||||
|
||||
|
||||
Reference in new issue
Block a user