Conversation
commit: |
88e32f9 to
9f838c1
Compare
Add { mode: "line" } option to render() that emits newline-separated
rows instead of CUP positioning sequences. Line mode writes every cell
and primes the front buffer, so subsequent diff renders work without
a full redraw.
This forces a render of all cells on the very first frame, which is perfectly acceptable.
Move the row offset from a constructor parameter to a render-time option. Row is now 1-based (matching ECMA-48 DSR/CPR format) so callers can pass the queried cursor position directly without conversion. Remove line mode from the inline region demo in favor of raw newline allocation followed by CUP rendering for all frames.
Rename csi.ts to termcodes.ts and add ESC(), SHOWCURSOR(), HIDECURSOR(), ALTSCREEN(), and MAINSCREEN() helpers. Make CursorEvent.row/column 1-based to match DSR native format. Replace all raw escape sequences in the demo with termcodes. Use DECSC/DECRC (ESC 7/8) for cursor save/restore instead of SCO (CSI s/u).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Clayterm currently renders using absolute CUP cursor positioning (
\x1b[row;colH), which only works in full-screen alternate buffer mode. This makes it unsuitable for "inline TUI" use cases where a program renders a small region in the normal terminal scrollback — like how Claude Code renders each tool call output inline, or how a CLI shows a spinner then commits the result to scrollback.Additionally, CUP sequences are meaningless when stdout is piped, so there's no way to produce pipe-friendly output.
Changes
Line rendering mode
Add a
{ mode: "line" }option torender()that emits newline-separated rows instead of CUP positioning sequences. This enables pipe-friendly output and front-buffer priming for efficient subsequent CUP diffs.1-based
rowrender optionMove the row offset from a constructor parameter to a render-time option (
{ row }) that is 1-based, matching the ECMA-48 DSR/CPR native format. Callers can pass the queried cursor position directly without conversion. Therowparameter is threaded through the C call chain (reduce→present_cups→emit_ch→emit_cursor) without struct mutation.CursorEventis now 1-basedCursorEvent.top/leftrenamed toCursorEvent.row/column, now 1-based to match DSR native format. The C parser no longer subtracts 1.termcodes.tsmoduleReplaces
csi.tswith a richer set of terminal escape code helpers:ESC(),CSI()— low-level sequence buildersDSR()— Device Status Report requestSHOWCURSOR(),HIDECURSOR()— DECTCEMALTSCREEN(),MAINSCREEN()— xterm private mode 1049saveCursorPosition()now uses DECSC/DECRC (ESC 7/ESC 8) instead of SCO (CSI s/CSI u)All helpers are documented with JSDoc linking to the relevant specs (ECMA-48, VT510, xterm).
Inline region demo
New
demo/inline-region.tsdemonstrates the region lifecycle: allocate space with raw newlines, DSR to compute the row, then CUP-render all frames at the offset. Includes spinner, progress bar, and nyan cat examples. Uses termcodes throughout instead of raw escape sequences.Other
cells_clear/cells_invalidateintocells_fill(buf, w, h, ch, fg, bg)Test plan
deno fmtanddeno lintclean