@yaks/tui 0.0.0-stage → 0.2.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/Frame.js +52 -0
  2. package/Frame.js.map +1 -0
  3. package/Frame.ts +92 -0
  4. package/Image.js +10 -0
  5. package/Image.js.map +1 -0
  6. package/Image.ts +22 -0
  7. package/LICENSE +202 -0
  8. package/README.md +524 -2
  9. package/RenderedCursor.js +103 -0
  10. package/RenderedCursor.js.map +1 -0
  11. package/RenderedCursor.ts +127 -0
  12. package/Scroll.js +88 -0
  13. package/Scroll.js.map +1 -0
  14. package/Scroll.ts +155 -0
  15. package/Textarea.js +186 -0
  16. package/Textarea.js.map +1 -0
  17. package/Textarea.ts +234 -0
  18. package/VirtualList.js +729 -0
  19. package/VirtualList.js.map +1 -0
  20. package/VirtualList.ts +838 -0
  21. package/_dist/Frame.d.ts +25 -0
  22. package/_dist/Frame.d.ts.map +1 -0
  23. package/_dist/Image.d.ts +13 -0
  24. package/_dist/Image.d.ts.map +1 -0
  25. package/_dist/RenderedCursor.d.ts +9 -0
  26. package/_dist/RenderedCursor.d.ts.map +1 -0
  27. package/_dist/Scroll.d.ts +30 -0
  28. package/_dist/Scroll.d.ts.map +1 -0
  29. package/_dist/Textarea.d.ts +26 -0
  30. package/_dist/Textarea.d.ts.map +1 -0
  31. package/_dist/VirtualList.d.ts +103 -0
  32. package/_dist/VirtualList.d.ts.map +1 -0
  33. package/_dist/guide.d.ts +21 -0
  34. package/_dist/guide.d.ts.map +1 -0
  35. package/_dist/history.d.ts +12 -0
  36. package/_dist/history.d.ts.map +1 -0
  37. package/_dist/input.d.ts +47 -0
  38. package/_dist/input.d.ts.map +1 -0
  39. package/_dist/interaction.d.ts +15 -0
  40. package/_dist/interaction.d.ts.map +1 -0
  41. package/_dist/keymap.d.ts +4 -0
  42. package/_dist/keymap.d.ts.map +1 -0
  43. package/_dist/mod.d.ts +42 -0
  44. package/_dist/mod.d.ts.map +1 -0
  45. package/_dist/mouse.d.ts +15 -0
  46. package/_dist/mouse.d.ts.map +1 -0
  47. package/_dist/paint.d.ts +86 -0
  48. package/_dist/paint.d.ts.map +1 -0
  49. package/_dist/print.d.ts +20 -0
  50. package/_dist/print.d.ts.map +1 -0
  51. package/_dist/run.d.ts +19 -0
  52. package/_dist/run.d.ts.map +1 -0
  53. package/_dist/screen.d.ts +22 -0
  54. package/_dist/screen.d.ts.map +1 -0
  55. package/_dist/scrollbar.d.ts +7 -0
  56. package/_dist/scrollbar.d.ts.map +1 -0
  57. package/_dist/testing.d.ts +19 -0
  58. package/_dist/testing.d.ts.map +1 -0
  59. package/_dist/theme.d.ts +11 -0
  60. package/_dist/theme.d.ts.map +1 -0
  61. package/_dist/visual.d.ts +28 -0
  62. package/_dist/visual.d.ts.map +1 -0
  63. package/deno.json +1 -0
  64. package/graphics.js +157 -0
  65. package/graphics.js.map +1 -0
  66. package/graphics.ts +191 -0
  67. package/grid.js +38 -0
  68. package/grid.js.map +1 -0
  69. package/grid.ts +46 -0
  70. package/guide.js +144 -0
  71. package/guide.js.map +1 -0
  72. package/guide.ts +169 -0
  73. package/history.js +58 -0
  74. package/history.js.map +1 -0
  75. package/history.ts +59 -0
  76. package/input.js +356 -0
  77. package/input.js.map +1 -0
  78. package/input.ts +324 -0
  79. package/interaction.js +180 -0
  80. package/interaction.js.map +1 -0
  81. package/interaction.ts +185 -0
  82. package/keymap.js +20 -0
  83. package/keymap.js.map +1 -0
  84. package/keymap.ts +23 -0
  85. package/mod.js +39 -0
  86. package/mod.js.map +1 -0
  87. package/mod.ts +92 -0
  88. package/mouse.js +65 -0
  89. package/mouse.js.map +1 -0
  90. package/mouse.ts +98 -0
  91. package/package.json +49 -4
  92. package/paint.js +1010 -0
  93. package/paint.js.map +1 -0
  94. package/paint.ts +1063 -0
  95. package/print.js +31 -0
  96. package/print.js.map +1 -0
  97. package/print.ts +40 -0
  98. package/run.js +220 -0
  99. package/run.js.map +1 -0
  100. package/run.ts +237 -0
  101. package/screen.js +97 -0
  102. package/screen.js.map +1 -0
  103. package/screen.ts +139 -0
  104. package/scrollbar.js +30 -0
  105. package/scrollbar.js.map +1 -0
  106. package/scrollbar.ts +33 -0
  107. package/table.js +134 -0
  108. package/table.js.map +1 -0
  109. package/table.ts +152 -0
  110. package/testing.js +86 -0
  111. package/testing.js.map +1 -0
  112. package/testing.ts +95 -0
  113. package/textRows.js +38 -0
  114. package/textRows.js.map +1 -0
  115. package/textRows.ts +31 -0
  116. package/theme.js +50 -0
  117. package/theme.js.map +1 -0
  118. package/theme.ts +39 -0
  119. package/visual.js +195 -0
  120. package/visual.js.map +1 -0
  121. package/visual.ts +209 -0
package/README.md CHANGED
@@ -1,3 +1,525 @@
1
- # Temporary Holding Version
1
+ # @yaks/tui
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ `@yaks/tui` renders Preact components in a terminal. Preact writes an in-memory
4
+ tree through the small DOM implementation in @yaks/dom; a `Backend` measures and
5
+ paints that tree. The included ANSI backend updates only changed terminal rows.
6
+
7
+ The package does not persist application data. Components keep transient input,
8
+ scroll, measurement, and selection state in memory. Applications own durable
9
+ data and pass it into their component tree.
10
+
11
+ ```ts ignore
12
+ import { createElement as h } from 'react'
13
+ import { Frame, run, Scroll, Textarea } from '@yaks/tui'
14
+
15
+ let App = () =>
16
+ h(
17
+ Frame,
18
+ { sidebar: [{ title: 'Status', Render: () => h('div', null, 'ok') }] },
19
+ h(Scroll, { id: 'log', grow: '1' }, h('div', null, 'hello')),
20
+ h(Textarea, { onSubmit: (text: string) => console.log(text) }),
21
+ )
22
+
23
+ await run(App)
24
+ ```
25
+
26
+ From this directory, run `deno task demo`. From the repository root, run
27
+ `deno task tui:demo`. The demo provides 500 scrollable transcript lines, a
28
+ multiline input, and two responsive sidebar panels. Press Ctrl+C to exit.
29
+
30
+ `@yaks/tui/guide` renders the kit’s style guide for `yak ui`.
31
+
32
+ The public entry point is `mod.ts`. It exports:
33
+
34
+ - application lifecycle: `run` and `quit`, and `print`, which paints a tree once
35
+ for a command that prints and exits (also `@yaks/tui/print`, without the
36
+ widgets);
37
+ - components and related types: `Frame`, `Panel`, `Scroll`, `View`, `Textarea`,
38
+ `VirtualList`, `VirtualWindow`, `VirtualItem`, `Anchor`, `Image`, and
39
+ `ImageSource`;
40
+ - rendering: `ansiBackend`, `Backend`, `Line`, `Seg`, `Metrics`, `lay`, `clip`,
41
+ `wrap`, `screenful`, `printout`, `ansi`, and `clipboard`;
42
+ - styling: widget defaults from `@yaks/tui/theme`, and `Sheet` and `Style` from
43
+ `@yaks/ui/sheet`;
44
+ - input and routing: `decode`, `feed`, `Input`, `Key`, `Mouse`, `MouseEvent`,
45
+ `Name`, `Keys`, `useKeys`, `useKeymap`, `press`, `pressTo`, `pressFocused`,
46
+ `hit`, and `routeMouse`;
47
+ - screen state: `size`, `metrics`, `terminalFocused`, `useMetric`, `measured`,
48
+ and `clear`;
49
+ - selection: `useVisualController`, `useTextSurface`, `emptyVisual`,
50
+ `VisualState`, `beginVisual`, `visualKey`, `copyText`, `RenderedCursor`, and
51
+ `TextPoint`;
52
+ - low-level DOM utilities: `doc`, `install`, `onPaint`, `touch`, `TNode`,
53
+ `TText`, and `TElement`;
54
+ - pure editor and scrolling helpers: `Edit`, `bol`, `eol`, `spot`, `edit`, and
55
+ `scrolled`.
56
+
57
+ Most applications need only `run` and the components. The lower-level exports
58
+ support custom backends, focused tests, and applications that own input routing.
59
+
60
+ ## Backend contract
61
+
62
+ ```ts
63
+ import type { Line, Metrics, TElement } from '@yaks/tui'
64
+
65
+ type Backend = {
66
+ control?: (body: string) => void
67
+ size: () => { columns: number; rows: number }
68
+ start: () => void
69
+ draw: (
70
+ root: TElement,
71
+ ) => { written: number; metrics: Metrics; lines?: Line[] }
72
+ reset: () => void
73
+ copy?: (text: string) => void
74
+ stop: () => void
75
+ }
76
+ ```
77
+
78
+ `run(App, { backend })` accepts a custom backend. `draw` receives the rendered
79
+ tree and returns the number of terminal rows written plus measurements for
80
+ elements with an `id`. Each measurement contains `{ total, height, width }`,
81
+ which lets scrolling components respond to layout without knowing terminal
82
+ dimensions themselves. Optional painted `lines` enable pointer hit testing.
83
+ `control` receives terminal protocol replies, and `copy` handles clipboard
84
+ requests. Widgets do not depend directly on ANSI escape sequences.
85
+
86
+ ## Layout
87
+
88
+ The painter recognizes these structural attributes:
89
+
90
+ | Attribute | Meaning |
91
+ | --------------- | ----------------------------------------------------------------- |
92
+ | `row` | Lay out element children side by side. |
93
+ | `col` | Stack element children vertically. |
94
+ | `width` | Reserve a fixed number of columns. |
95
+ | `grow` | Use space left by fixed siblings. |
96
+ | `grow-fit` | In a column, shrink to content within the element's share. |
97
+ | `wrap` | Wrap at word boundaries and split words longer than the width. |
98
+ | `height` | Reserve a fixed number of rows. |
99
+ | `max-height` | Cap rows without padding shorter content. |
100
+ | `overflow-text` | Add a final plain-text row when `max-height` clips content. |
101
+ | `scroll` | Display content starting at a row offset and report measurements. |
102
+ | `fill` | Extend the inherited style across the available row width. |
103
+
104
+ Block elements stack as rows. Inline elements such as `span`, `b`, `i`, `a`,
105
+ `button`, and `label` share a row. `pre` preserves newlines. A class name looks
106
+ up a `Style` in the active `Sheet`. A wrapper with one element child passes its
107
+ box to that child.
108
+
109
+ A `Style` can say `row`, `col`, `width`, `grow`, `wrap` and `border` too, so a
110
+ part drawn in a browser and a terminal alike (@yaks/ui) keeps its terminal
111
+ layout in its sheet, beside its colours, and puts nothing in the browser's DOM
112
+ for it: `{ Panes: { row: true }, 'Panes_Pane-nav': { col: true, width: 30 } }`.
113
+
114
+ Three more say what CSS says of a grid. `grid` lays every `row` under an element
115
+ (through whatever holds it, a head or a body) in shared columns, two apart, as
116
+ subgrid rows share a CSS grid's tracks: each column grows toward its widest
117
+ cell, all by the same step, as far as the room allows, a `width` fixes one and a
118
+ `grow` one takes what is left (`grid.ts`), and a row's colours run under its
119
+ gaps. `ellipsis` ends a line cut to its width in `…`, as `text-overflow` does,
120
+ and `align` sets an element narrower than its width to one side, as `text-align`
121
+ does.
122
+
123
+ Semantic `strong`, `em`, `del`, headings, links, code, block quotes, rules, and
124
+ tables receive terminal-specific rendering without requiring application
125
+ components to emit ANSI. A bare `a`, one with no class, wears the sheet's `Link`
126
+ (the link colour, in @yaks/ui's sheet); an anchor with a class is a part that
127
+ says its own look there. A text field (`input`, `textarea`) shares a row and
128
+ paints what a browser shows in it: its `value`, or its `placeholder` in the
129
+ `Entry_Hint` style while empty. A terminal has no focus to show the caret by, so
130
+ a field carrying `data-caret` paints the `Cursor` cell at that offset.
131
+
132
+ ## Style
133
+
134
+ `theme.ts` exports the `Sheet` and `Style` types and `base`, what this package's
135
+ widgets are without colour: the painted cursor is inverse, a table header bold.
136
+ Class names use the repository's `Block_Element-modifier` convention. Pass
137
+ `sheet` to `run` or `ansiBackend`; its entries replace `base` entries with the
138
+ same names. A sheet given as a function is read at every paint, so an app can
139
+ change its theme while it runs. Colours come from a theme: `@yaks/ui` builds a
140
+ sheet for its components and these widgets from a composition
141
+ (`sheet({ kits, theme: everforest })`, importing `kits`, `sheet` and
142
+ `everforest` from `@yaks/ui`).
143
+
144
+ A `Style` may set `fg`, `bg`, `bold`, `dim`, `italic`, `underline`, `strike`,
145
+ `inverse`, `glyph`, `indent`, `gap`, `block`, which lays an inline tag (a
146
+ `button`, a `span`) out on lines of its own, as CSS's `display: block` does, and
147
+ `hidden`, which paints nothing and takes no room, as `display: none` does. The
148
+ painter also uses `href` internally for sanitized links. A closed `details`
149
+ paints its `summary` alone, and a summary paints `▸` before it, `▾` while its
150
+ `details` is open, as a browser's do.
151
+
152
+ ## Widgets
153
+
154
+ - `Scroll` displays a window over its children. It follows appended content
155
+ while positioned at the bottom. Arrow keys, page keys, Ctrl+Home/Ctrl+End, and
156
+ the mouse wheel change its offset. Set `follow={false}` for content that
157
+ should open at the top, `keyboard={false}` when another component owns keys,
158
+ or `scrollbar` to reserve a visual scrollbar column. `scrolled` exposes its
159
+ offset calculation as a pure function.
160
+ - `Textarea` is a multiline editor. Enter submits and Shift+Enter or Alt+Enter
161
+ inserts a newline. It supports navigation, word movement and deletion,
162
+ Ctrl+A/E/U/K/W, bracketed paste, soft wrapping, and a painted cursor. `max`
163
+ limits its visible rows. The pure helpers `edit`, `bol`, `eol`, and `spot`
164
+ support editor tests and custom controls.
165
+ - `Frame` places application content beside an optional right sidebar. Each
166
+ `Panel` supplies a `title` and Preact `Render` component. The sidebar is
167
+ hidden below `min` terminal columns.
168
+ - `VirtualList` renders only enough stable-ID items to fill its viewport. Use it
169
+ for large transcripts or lists whose items are static presentation.
170
+ - `Image` reserves terminal cells for an asynchronously loaded PNG when Kitty
171
+ graphics are enabled and otherwise displays its fallback label.
172
+
173
+ `useKeys(handler)` registers a handler while its component is mounted. Newer
174
+ handlers run first, and a falsy return passes the key to the next handler.
175
+ `press(key)` starts normal routing. `size` is a signal containing terminal
176
+ dimensions; `useMetric(id)` returns the last layout measurement for an element.
177
+
178
+ ## The boundary
179
+
180
+ Before painting, the backend removes C0, DEL, and C1 control characters from
181
+ text and link targets with `@yaks/text`. Newlines remain line breaks and tabs
182
+ become two spaces. All terminal escape sequences originate in backend code,
183
+ including `ansi`, drawing, graphics, and clipboard output.
184
+
185
+ ## Focus, measuring and keys
186
+
187
+ The document does what a browser does for a page's own scripts. `focus()` takes
188
+ the focus from whatever held it, sending `focus` and `focusin`, and `blur()`
189
+ lets it go with `blur` and `focusout`; the painter shows the element in focus
190
+ inverse (never a box with `tabindex="-1"`, focused only to hear keys), and the
191
+ element vim's cursor stands on (`data-cursor`) too. `scrollIntoView()` keeps an
192
+ element in sight, the scroll region around it showing it on the next paint.
193
+ `click()` presses it as a browser's click does: a check box flips and a radio
194
+ turns on (back again when a listener cancels it, else telling its `input` and
195
+ `change`; `checked` is its attribute), a submit button submits its form, a
196
+ `details`' `summary` opens or closes it (its `open` attribute), and a link no
197
+ listener took is followed: `onNavigate` names where. `isConnected` is whether a
198
+ node hangs under a screen's root; `contentEditable` and `isContentEditable` read
199
+ and set text typed over in place, and `textContent` sets an element's text.
200
+ After each paint, `place(lines, hidden)` records what was painted:
201
+ `getBoundingClientRect()` is then the cells an element and everything inside it
202
+ painted (an empty box at the origin out of a window's sight), and
203
+ `checkVisibility()` is false where the sheet hid it or what holds it. `run` and
204
+ the test `mount` record every paint; a test painting with `screenful` calls
205
+ `place` itself. Attribute names are lowercased, as an HTML document's are.
206
+
207
+ `@yaks/tui/interaction` is what a browser does for its controls by itself: Tab
208
+ and Shift-Tab walk them, Enter and Space press one, a field takes what is typed
209
+ (text typed over in place too, its caret painted as a field's), arrows choose a
210
+ select's option, Escape lets go. Every key reaches the element in focus first as
211
+ a keydown, so a page's own listeners hear it as they would in a browser; vim's
212
+ keys over a page are [@yaks/ux](../ux/README.md)'s.
213
+
214
+ ## Compatibility
215
+
216
+ `run` currently requires Deno because it uses `Deno.stdin`, `Deno.consoleSize`,
217
+ and signal listeners. The DOM, input decoder, painter, and widgets accept
218
+ injected data and can be used in another runtime, but that runtime must provide
219
+ its own terminal input and lifecycle adapter.
220
+
221
+ ### Lazy lists
222
+
223
+ Each `VirtualList` item must have a stable string `id`. Pass `renderItem` to
224
+ produce its Preact content and optionally pass `version(item)` when content can
225
+ change without its ID changing. The default version is `JSON.stringify(item)`.
226
+ Use `follow` for a transcript that starts and remains at the end; otherwise the
227
+ list starts at its first item.
228
+
229
+ The viewport stores an item ID and visual-row offset instead of a global row
230
+ number. Changes before that item therefore preserve the visible position.
231
+ Removing the anchor selects its former successor or the last remaining item.
232
+ Changing the list component's `id` resets its viewport.
233
+
234
+ Opening at the bottom measures backward only until the screen is full. The list
235
+ does not calculate every earlier item height or mount every item. It retains up
236
+ to 256 Preact trees and 256 laid-out items in separate least-recently-used
237
+ caches. A resize or theme change lays out visible cached trees again; a changed
238
+ version rebuilds the affected tree. Render item content as static presentation,
239
+ and include revisions of external dependencies in `version`.
240
+
241
+ The application still owns the complete item array. Replacing that array builds
242
+ an O(N) ID index; passing the same array does not. Cache limits count items, so
243
+ one very large item can still consume substantial memory.
244
+
245
+ ### Pointer routing
246
+
247
+ `decode` and `feed` return `Input`, which is `Key | Mouse`. Check
248
+ `input.name === 'mouse'` before passing keyboard input to `press`. SGR mouse
249
+ reports contain zero-based coordinates, button data, modifiers, release state,
250
+ event type, and signed wheel movement.
251
+
252
+ The ANSI backend attaches owning elements to its clipped painted lines.
253
+ `routeMouse` hit-tests those cells and bubbles `onClick`, `onWheel`,
254
+ `onMouseDown`, `onMouseUp`, and `onMouseMove` through `TElement.parentNode`.
255
+ Handlers receive `target`, `currentTarget`, `preventDefault`, and
256
+ `stopPropagation`; returning `true` also consumes the event. This is a small
257
+ bubbling event system rather than a browser event model. A backend without
258
+ painted `lines` still supports keyboard input but cannot target pointers.
259
+
260
+ `Scroll` and `VirtualList` handle unmodified vertical wheel reports over their
261
+ painted region. At a known boundary, the report can bubble to an enclosing
262
+ scroll region. Virtual-list item trees are detached from the main tree, so their
263
+ painted cells target the list element.
264
+
265
+ The ANSI backend enables terminal modes 1000 and 1006 and restores their saved
266
+ values on shutdown. It decodes motion reports if a terminal sends them, but does
267
+ not request motion reporting. Coordinates use JavaScript string lengths; wide
268
+ glyphs and combining characters can therefore misalign. Pointer capture,
269
+ capture-phase listeners, and horizontal scrolling are not implemented.
270
+
271
+ ### Optional scrollbars
272
+
273
+ Set `scrollbar` on `Scroll` or `VirtualList` to reserve one column for a
274
+ three-row thumb on a `│` track. Very short viewports clamp the thumb, and widths
275
+ under two columns omit it. `Scrollbar` and `Scrollbar_Snapped` style the bar;
276
+ following the end uses the snapped style. The scrollbar does not support
277
+ dragging or click-to-jump.
278
+
279
+ `VirtualList` estimates unmeasured item heights from its bounded measurement
280
+ cache. The estimate can change as items are visited, but it does not move the
281
+ item-relative viewport anchor or trigger offscreen layout.
282
+
283
+ ### Characterwise VISUAL selection
284
+
285
+ An application can store `VisualState` and register it with
286
+ `useVisualController(get, set)`. `useTextSurface` registers a selectable text
287
+ region. `Textarea` registers its draft automatically; `VirtualList` registers
288
+ item source only when passed `textOf(item)`.
289
+
290
+ Alt+V enters source selection or cycles regions. Tab cycles registered regions;
291
+ H/J/K/L or arrows extend an inclusive selection; Home/End move to row edges; `[`
292
+ and `]` select adjacent items when available; `y` copies and exits; Escape
293
+ cancels. Outside this mode, ordinary editing keys keep their normal behavior.
294
+
295
+ During source selection, the active region displays its source as wrapped plain
296
+ text with an inverse selection. Copied text excludes ANSI, borders, and rendered
297
+ metadata and preserves explicit newlines without adding soft-wrap newlines.
298
+ Selection is limited to one surface or item. Moving through source does not
299
+ change a virtual list's normal scroll anchor.
300
+
301
+ Copying asks the ANSI backend to write OSC52. The terminal may reject or
302
+ truncate the request without acknowledgement. iTerm2 clipboard permission and
303
+ tmux OSC52 support may need configuration. Applications can provide a custom
304
+ backend `copy` method. The test harness records its last requested copy in the
305
+ ephemeral `visual.yank` field.
306
+
307
+ Only one visual controller may be active for a terminal. Mouse selection is not
308
+ implemented. Positions use UTF-16 columns instead of grapheme or terminal-cell
309
+ widths, and the controller's `get` function must return current state
310
+ synchronously.
311
+
312
+ ## Inline images (experimental)
313
+
314
+ `Image` accepts an `ImageSource` containing a stable `key`, asynchronous
315
+ `load(): Promise<Uint8Array>`, fallback `alt` text, and fixed cell height in
316
+ `rows`. Set `graphics: 'kitty'` on `run` or `ansiBackend`; set `tmux: true` when
317
+ tmux DCS passthrough is required. Graphics default to disabled, with no
318
+ capability probe.
319
+
320
+ An image loads only when its complete reserved rectangle is visible. Clipped or
321
+ unvisited images retain a text fallback. The backend caches uploaded bytes,
322
+ updates placement after text or size changes, and deletes placements when an
323
+ image moves, unmounts, or the backend stops.
324
+
325
+ Only PNG is supported. Uploads are limited to 4 MiB, declared pixel area to 32
326
+ megapixels, height to 1–16 terminal rows, and the cache to eight images or 32
327
+ MiB of source bytes. The terminal performs PNG decoding; local signature and
328
+ dimension checks are not full validation. A failed load stays failed until that
329
+ cache entry is replaced.
330
+
331
+ Applications must configure compatible terminals. tmux may require
332
+ `set -g allow-passthrough on`. iTerm2's OSC 1337 image protocol is not
333
+ implemented.
334
+
335
+ Kitty APC replies are terminal protocol data. `feed` consumes complete,
336
+ fragmented, and tmux-wrapped replies before key routing. Known upload errors
337
+ change the fallback label. A “Kitty image sent” label only confirms that the
338
+ backend wrote protocol commands; it does not confirm display by the terminal.
339
+
340
+ ### Modified Enter
341
+
342
+ `feed` preserves CSI keyboard sequences across input chunks, including Kitty
343
+ `CSI 13;2u` and xterm `CSI 27;2;13~` for Shift+Enter. It also recognizes
344
+ Alt+Enter in CSI and legacy Escape-prefixed CR/LF forms. Complete sequences are
345
+ returned immediately; incomplete CSI sequences remain buffered without extending
346
+ the 25 ms timeout used to distinguish a bare Escape key.
347
+
348
+ If a terminal sends bare CR or LF for Shift+Enter, the modifier is absent and
349
+ cannot be reconstructed. Enable the terminal's extended-key reporting or reset
350
+ the terminal session.
351
+
352
+ ### Compact sidebars and controlled shortcuts
353
+
354
+ A bounded `Frame` panel can set `fit: true` to use its natural content height up
355
+ to an equal share of available rows. Other bounded panels receive unused rows,
356
+ and overflow still scrolls. Panel order is display order, so a summary placed
357
+ last remains below a growing panel.
358
+
359
+ The `grow-fit="1"` layout attribute provides the same behavior in any column.
360
+ `fill="1"` extends inherited styling through the row's available width.
361
+
362
+ `Textarea` accepts `passKey(key)`. Returning true leaves that key for another
363
+ mounted handler, which lets applications reserve shortcuts while retaining the
364
+ editor's default bindings.
365
+
366
+ ## Controlled keyboard routing
367
+
368
+ `useKeymap(handler)` installs a mounted interceptor before widget focus and
369
+ source-selection handling. Return true to consume a key. Keep application mode
370
+ state outside this package; unmounting the hook restores normal routing.
371
+
372
+ `useKeys(handler, id)` assigns a stable target. `pressTo(id, key)` sends a key
373
+ to that target without changing focus. `pressFocused(key)` continues routing an
374
+ already intercepted key without invoking interceptors again. `beginVisual(id)`
375
+ starts source selection on a registered surface. Set a controlled `Textarea`'s
376
+ `active` prop to false when another mode should hide its cursor.
377
+
378
+ ### Clipboard requests
379
+
380
+ `copyText(text)` asks the backend installed by `run` to copy text. Its boolean
381
+ return reports whether a clipboard writer exists, not whether the terminal
382
+ accepted the content. The ANSI backend emits UTF-8 text as base64 OSC52. Callers
383
+ must retain any local recovery buffer before clearing editable text.
384
+
385
+ ## Tables
386
+
387
+ Semantic `table`, `thead`, `tbody`, `tfoot`, `tr`, `th`, and `td` elements use
388
+ measured columns. Header cells are bold; `Table_Header` and `Table_Border`
389
+ control their styles. Cells preserve text styles, links, and explicit line
390
+ breaks and wrap words and long runs. Set `align` to `left`, `center`, or
391
+ `right`; the painter also recognizes CSS `text-align` written by shared
392
+ renderers.
393
+
394
+ Tables fill available content width. Initial widths sample at most 32 rows and
395
+ 128 text positions or nodes per cell, with sampled content widths capped at 40
396
+ positions. Later or longer values wrap. Missing cells remain empty. When the
397
+ available width cannot contain columns and borders, each row becomes a stacked
398
+ record with repeated header labels.
399
+
400
+ Nested tables use their container's remaining width. A table inside one
401
+ virtual-list item is fully laid out when that item is measured; its rows are not
402
+ separately virtualized. Row spans, column spans, and CSS table sizing are not
403
+ supported. Width uses UTF-16 code units, so CJK characters, combining marks, and
404
+ emoji can misalign.
405
+
406
+ ### Code block backgrounds
407
+
408
+ Semantic `pre` elements fill available width, including blank rows, with the
409
+ `Code` style of the sheet; inline `code` styles only its text. Borders and
410
+ indentation reduce available width. Existing wrapping or clipping behavior still
411
+ controls long source lines.
412
+
413
+ ### Proportional terminal sidebar
414
+
415
+ `Frame` uses a 30-column sidebar by default. Set `ratio={0.2}` to request 20% of
416
+ terminal columns, rounded down. `width` then acts as a minimum, and the frame
417
+ always leaves at least one terminal column for main content. The sidebar remains
418
+ hidden below `min`, which defaults to 90 columns.
419
+
420
+ The ratio and visibility threshold use terminal dimensions, not a nested
421
+ container's width. Nested layouts should use row and column attributes or a
422
+ fixed `width`.
423
+
424
+ ### Controlled item selection
425
+
426
+ Pass `selected` and `onSelect(id)` to `VirtualList` for controlled item
427
+ selection. Up/Down select adjacent items, Home/End select endpoints,
428
+ PageUp/PageDown move about one viewport, and Ctrl+U/D move about half a
429
+ viewport. Distances use average measured item heights and do not measure unseen
430
+ items. `List_Selected` styles the selection. A changed selection is revealed;
431
+ the mouse wheel may then scroll away from it. Without `onSelect`, the same keys
432
+ scroll by rendered rows.
433
+
434
+ ### Graceful quit
435
+
436
+ Ctrl+C is the process's interrupt, the same one SIGTERM, SIGINT or SIGHUP is
437
+ (`@yaks/process/wind`), and the terminal holds the process open while it winds
438
+ down. A component that is still finishing something calls
439
+ `useHold(drain, force)`: the first interrupt stops ordinary input routing and
440
+ waits for every `drain`, then the app exits; a second calls each `force` and
441
+ exits without waiting. The application may update its existing view state while
442
+ it drains. With nothing held, Ctrl+C exits at once. Errors still restore
443
+ terminal state.
444
+
445
+ ### Partially loaded virtual lists
446
+
447
+ For paged data, pass `range: { before, after }` and `onRange(request)`. The
448
+ flags say whether unloaded neighbors exist. Near a visible boundary, or after a
449
+ Home/End request, the list asks the application for overlapping data. The
450
+ application fetches it, preserves the controlled viewport anchor, and replaces
451
+ `items`.
452
+
453
+ Set `pending` while replacing a requested page. The list retains its last
454
+ painted viewport and scrollbar during that transition; an initially pending list
455
+ displays `Loading…`. Pending lists ignore navigation and do not publish
456
+ normalized viewport positions. Set `pending={false}` for a completed empty
457
+ result so old content is cleared. Changing the list `id` also clears the paint
458
+ cache.
459
+
460
+ The widget does not fetch or store application records. It retains only
461
+ identity, selection, viewport, rendered-line caches, and measurements needed for
462
+ display.
463
+
464
+ ### Terminal focus and the input caret
465
+
466
+ The ANSI backend enables terminal focus reporting and restores the saved mode on
467
+ shutdown. `terminalFocused` is a signal independent of widget focus. `Textarea`
468
+ hides its synthetic block cursor on focus-out and restores it on focus-in
469
+ without changing text or cursor position. Focus reports are consumed before
470
+ keyboard routing.
471
+
472
+ If no reports arrive, the terminal is considered focused. tmux may require
473
+ `set -g focus-events on`; the application does not change tmux configuration.
474
+
475
+ ### Mouse clicks
476
+
477
+ Preact `onClick` handlers receive unmodified primary-button clicks through the
478
+ same clipped hit testing and bubbling used for wheel events. The press and
479
+ release must occur on the same clickable element or its inline child. Right
480
+ clicks, modifier-assisted clicks, and drags do not activate it. Unmounting
481
+ clears an unfinished press. Source-selection mode suppresses mouse navigation.
482
+
483
+ Virtualized item contents target the list element, so controls inside an item do
484
+ not receive individual clicks. Mouse text selection is not implemented.
485
+
486
+ `max-height` caps any block without padding shorter content. Optional
487
+ `overflow-text` adds a plain-text final row only when content is clipped. The
488
+ source data is unchanged.
489
+
490
+ ### Rendered text cursor
491
+
492
+ `VirtualList` can accept a controlled `cursor`, `onCursor`, and `onYank`.
493
+ `RenderedCursor` contains an item `id`, local rendered `row`, UTF-16 `col`, and
494
+ an optional selection `anchor`. With these props, arrows move through rendered
495
+ lines. Movement measures only visited items and requests neighboring data
496
+ through `onRange`. `v` begins a range, `y` copies it, and Escape clears it; the
497
+ application chooses any additional aliases and stores cursor state.
498
+
499
+ Cursor styling decorates cached lines without reparsing item content.
500
+ `Seg.decorative` excludes generated borders and padding from copied text, while
501
+ `Seg.softBreak` distinguishes wrapping from source line breaks. Copies contain
502
+ displayed text rather than Markdown syntax; table copies contain visible cell
503
+ text and spacing.
504
+
505
+ A selection may span overlapping loaded pages while their measured lines remain
506
+ cached. Missing or evicted endpoints produce an error instead of truncated text.
507
+ Copies are limited to 65,536 UTF-16 code units. Resize and reflow clamp
508
+ positions but do not preserve a semantic character offset. Surrogate pairs stay
509
+ together; other terminal-width limitations still apply.
510
+
511
+ ### Estimated virtual scroll ranges
512
+
513
+ A partial `VirtualList` may include `range.total`, the complete logical item
514
+ count, and `range.offset`, the logical index of the first loaded item. Supply
515
+ both together with `before` and `after`. The scrollbar estimates unknown item
516
+ heights from measured averages and retains numeric heights after rendered text
517
+ leaves the bounded cache. Drawing it does not measure more items or move the
518
+ viewport anchor.
519
+
520
+ Height metadata grows with visited items and contains numbers rather than item
521
+ text. Width or theme changes invalidate it, and a changed item version is
522
+ remeasured when revisited. Insertions or removals outside a loaded page can make
523
+ remembered estimates temporarily approximate. Without total and offset, the list
524
+ uses its neighboring-page estimate. The three-row terminal thumb remains an
525
+ approximate row-level indicator.
@@ -0,0 +1,103 @@
1
+ /** Cursor/selection over styled layout lines. No graph or Markdown dependency. */ // Decorations occupy cells but never enter a copied selection.
2
+ export let textLength = (line)=>line.reduce((n, s)=>n + s.text.length, 0);
3
+ export let clampPoint = (p, lines)=>{
4
+ let row = Math.max(0, Math.min(lines.length - 1, p.row));
5
+ let text = (lines[row] ?? []).map((s)=>s.text).join('');
6
+ let col = Math.max(0, Math.min(Math.max(0, text.length - 1), p.col));
7
+ // Never leave the cursor on the low half of a surrogate pair.
8
+ if (col && /[\uDC00-\uDFFF]/.test(text[col])) col--;
9
+ return {
10
+ ...p,
11
+ row,
12
+ col
13
+ };
14
+ };
15
+ export let stepColumn = (line, col, delta)=>{
16
+ let text = line.map((s)=>s.text).join('');
17
+ let next = col + delta;
18
+ if (delta > 0 && /[\uD800-\uDBFF]/.test(text[col] ?? '')) next++;
19
+ if (delta < 0 && /[\uDC00-\uDFFF]/.test(text[next] ?? '')) next--;
20
+ return Math.max(0, Math.min(Math.max(0, text.length - 1), next));
21
+ };
22
+ export let comparePoint = (a, b, ids)=>ids.indexOf(a.id) - ids.indexOf(b.id) || a.row - b.row || a.col - b.col;
23
+ /** Decorate without changing the measured/cached lines. */ export let cursorLine = (line, id, row, cursor, ids, style)=>{
24
+ const anchor = cursor.anchor;
25
+ const [low, high] = anchor && comparePoint(anchor, cursor, ids) < 0 ? [
26
+ anchor,
27
+ cursor
28
+ ] : [
29
+ cursor,
30
+ anchor ?? cursor
31
+ ];
32
+ const index = ids.indexOf(id), lowIndex = ids.indexOf(low.id), highIndex = ids.indexOf(high.id);
33
+ const inRange = index >= lowIndex && index <= highIndex;
34
+ let col = 0;
35
+ const result = [];
36
+ for (let seg of line){
37
+ for (let text of seg.text){
38
+ const active = anchor && inRange && (index > lowIndex || row > low.row || row == low.row && col >= low.col) && (index < highIndex || row < high.row || row == high.row && col <= high.col);
39
+ const caret = id == cursor.id && row == cursor.row && col == cursor.col;
40
+ result.push({
41
+ ...seg,
42
+ text,
43
+ style: {
44
+ ...seg.style,
45
+ ...active ? {
46
+ inverse: true
47
+ } : {},
48
+ ...caret ? style : {}
49
+ }
50
+ });
51
+ col += text.length;
52
+ }
53
+ }
54
+ if (!col && id == cursor.id && row == cursor.row) {
55
+ result.push({
56
+ text: ' ',
57
+ style,
58
+ decorative: true
59
+ });
60
+ }
61
+ return result;
62
+ };
63
+ /** Bounded displayed-text copy. Missing/unloaded endpoints are an error, not truncation. */ export let copyRendered = (cursor, ids, read, limit = 65536)=>{
64
+ let a = cursor.anchor ?? cursor, b = cursor;
65
+ if (!ids.includes(a.id) || !ids.includes(b.id)) {
66
+ throw new Error('Selection exceeds retained text; select a smaller range');
67
+ }
68
+ if (comparePoint(a, b, ids) > 0) [a, b] = [
69
+ b,
70
+ a
71
+ ];
72
+ let rows = [], size = 0, soft = false;
73
+ for(let i = ids.indexOf(a.id); i <= ids.indexOf(b.id); i++){
74
+ const id = ids[i], lines = read(id);
75
+ if (!lines) throw new Error('Selection text is no longer retained');
76
+ for(let row = id == a.id ? a.row : 0; row <= (id == b.id ? b.row : lines.length - 1); row++){
77
+ let col = 0, text = '', hasText = false;
78
+ for (const seg of lines[row] ?? []){
79
+ for (const char of seg.text){
80
+ const selected = !(id == a.id && row == a.row && col < a.col) && !(id == b.id && row == b.row && col > b.col);
81
+ if (selected && !seg.decorative) {
82
+ text += char;
83
+ hasText = true;
84
+ }
85
+ col += char.length;
86
+ }
87
+ }
88
+ // Skip pure border rows, preserve empty content rows.
89
+ if (hasText || !(lines[row] ?? []).length) {
90
+ size += text.length + 1;
91
+ if (size > limit) {
92
+ throw new Error('Selection exceeds 65,536 characters; select a smaller range');
93
+ }
94
+ const nextSoft = (lines[row] ?? []).some((seg)=>seg.softBreak);
95
+ if (soft && rows.length) rows[rows.length - 1] += text;
96
+ else rows.push(text);
97
+ soft = nextSoft;
98
+ }
99
+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