@kolisachint/hoocode-tui 0.5.66 → 0.5.68

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 (39) hide show
  1. package/dist/components/editor.d.ts +20 -18
  2. package/dist/components/editor.d.ts.map +1 -1
  3. package/dist/components/editor.js +54 -58
  4. package/dist/components/editor.js.map +1 -1
  5. package/dist/components/frame.d.ts +117 -0
  6. package/dist/components/frame.d.ts.map +1 -0
  7. package/dist/components/frame.js +203 -0
  8. package/dist/components/frame.js.map +1 -0
  9. package/dist/components/select-list.d.ts.map +1 -1
  10. package/dist/components/select-list.js +8 -2
  11. package/dist/components/select-list.js.map +1 -1
  12. package/dist/components/settings-list.d.ts.map +1 -1
  13. package/dist/components/settings-list.js +7 -2
  14. package/dist/components/settings-list.js.map +1 -1
  15. package/dist/index.d.ts +3 -1
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +4 -1
  18. package/dist/index.js.map +1 -1
  19. package/dist/keybindings.d.ts +9 -4
  20. package/dist/keybindings.d.ts.map +1 -1
  21. package/dist/keybindings.js +14 -2
  22. package/dist/keybindings.js.map +1 -1
  23. package/dist/mouse.d.ts +75 -0
  24. package/dist/mouse.d.ts.map +1 -0
  25. package/dist/mouse.js +115 -0
  26. package/dist/mouse.js.map +1 -0
  27. package/dist/terminal.d.ts +30 -0
  28. package/dist/terminal.d.ts.map +1 -1
  29. package/dist/terminal.js +49 -0
  30. package/dist/terminal.js.map +1 -1
  31. package/dist/tui.d.ts +286 -0
  32. package/dist/tui.d.ts.map +1 -1
  33. package/dist/tui.js +642 -1
  34. package/dist/tui.js.map +1 -1
  35. package/dist/undo-stack.d.ts +39 -6
  36. package/dist/undo-stack.d.ts.map +1 -1
  37. package/dist/undo-stack.js +59 -6
  38. package/dist/undo-stack.js.map +1 -1
  39. package/package.json +1 -1
package/dist/tui.d.ts CHANGED
@@ -51,6 +51,34 @@ export declare function isFocusable(component: Component | null): component is C
51
51
  * TUI finds and strips this marker, then positions the hardware cursor there.
52
52
  */
53
53
  export declare const CURSOR_MARKER = "\u001B_pi:c\u0007";
54
+ /** What the scroll indicator is told about the pinned view. */
55
+ export interface ScrollStatus {
56
+ /** 1-based transcript row at the top of the view. */
57
+ top: number;
58
+ /** 1-based transcript row at the bottom of the view. */
59
+ bottom: number;
60
+ /** Rows in the whole transcript. */
61
+ total: number;
62
+ /** Rows the view shows at once. */
63
+ viewHeight: number;
64
+ atTop: boolean;
65
+ /** True only when the very last row is in view — the point where the pin lets go. */
66
+ atBottom: boolean;
67
+ /** Columns the indicator may fill. */
68
+ width: number;
69
+ /** Present while a search is running; the indicator becomes its query line. */
70
+ search?: ScrollSearchStatus;
71
+ }
72
+ export interface ScrollSearchStatus {
73
+ query: string;
74
+ /** Rows containing a match. */
75
+ count: number;
76
+ /** 1-based position among the matches, or 0 when there are none. */
77
+ index: number;
78
+ /** True while the query is still being typed. */
79
+ typing: boolean;
80
+ }
81
+ export type ScrollStatusFormatter = (status: ScrollStatus) => string;
54
82
  /**
55
83
  * Anchor position for overlays
56
84
  */
@@ -125,6 +153,60 @@ export declare class Container implements Component {
125
153
  removeChild(component: Component): void;
126
154
  clear(): void;
127
155
  invalidate(): void;
156
+ /**
157
+ * Where each direct child's output starts, in rows, from the last render.
158
+ *
159
+ * Read off the memo rather than recomputed, so asking is a walk over the
160
+ * children's cached line arrays and never a re-render. Undefined before the
161
+ * first render, or at a different width than the caller has in mind — both
162
+ * cases mean "no answer", not "zero".
163
+ *
164
+ * This is what lets something outside the tree point at a row inside it: a
165
+ * component's offset within its container, plus that container's offset at
166
+ * the root, is its absolute row in the buffer the viewport windows over.
167
+ */
168
+ childRowOffsets(width: number): number[] | undefined;
169
+ render(width: number): string[];
170
+ }
171
+ /**
172
+ * A child that can be taken off screen without disturbing the diff.
173
+ *
174
+ * Hiding a component naively — returning `[]` from its render — is one of the
175
+ * more expensive things you can do to this renderer. `Container.render` and the
176
+ * root's flat cache both decide "did this subtree change" by **array identity**,
177
+ * so a fresh `[]` every frame reads as a change every frame: the memo is
178
+ * dropped, the buffer is re-flattened, and a dirty range is reported for a
179
+ * component that is not even drawn. One frozen array, returned every time,
180
+ * makes a hidden slot free instead.
181
+ *
182
+ * The child is not rendered at all while hidden, which is the other half of the
183
+ * saving — a hidden footer costs nothing to keep hidden. That means a child
184
+ * whose `render` advances an animation or maintains a cache will be paused, not
185
+ * merely invisible; it catches up when shown again. Chrome (footers, panels,
186
+ * status rows) is fine with that. A spinner is not, so do not wrap one.
187
+ */
188
+ export declare class Slot implements Component {
189
+ private component;
190
+ /** Shared across every hidden slot: identity is all the caches compare. */
191
+ private static readonly EMPTY;
192
+ private hidden;
193
+ constructor(component: Component);
194
+ /** Whoever is in the slot right now. */
195
+ get child(): Component;
196
+ /**
197
+ * Swap the occupant, keeping the slot itself in place.
198
+ *
199
+ * An extension replacing the footer used to remove one root child and append
200
+ * another, which both moved the footer to the end of the tree — behind the
201
+ * widgets meant to sit below it — and handed the root's per-child cache a
202
+ * changed child list every time. The slot is the stable root child; only what
203
+ * is inside it changes.
204
+ */
205
+ setChild(component: Component): boolean;
206
+ get visible(): boolean;
207
+ /** Returns whether this changed anything, so callers can skip a render. */
208
+ setVisible(visible: boolean): boolean;
209
+ invalidate(): void;
128
210
  render(width: number): string[];
129
211
  }
130
212
  /**
@@ -169,10 +251,153 @@ export declare class TUI extends Container {
169
251
  private previousViewportTop;
170
252
  private fullRedrawCount;
171
253
  private stopped;
254
+ /**
255
+ * The pinned viewport.
256
+ *
257
+ * ## What is wrong with letting the terminal do it
258
+ *
259
+ * This renderer keeps the entire transcript in its line buffer and writes it
260
+ * to the normal screen, so "scrolling" has always meant the terminal's own
261
+ * scrollback. That works exactly as long as the app does not repaint — and
262
+ * this one repaints the whole buffer whenever a line *above* the viewport
263
+ * changes, because a positional diff cannot address a row that has scrolled
264
+ * out of reach. The repaint is `\x1b[2J\x1b[H\x1b[3J` followed by the
265
+ * transcript again, and the `\x1b[3J` throws away the scrollback the reader
266
+ * was sitting in. From the reader's side the screen simply jumps to the
267
+ * bottom, for no reason they can see, at a moment they did not choose.
268
+ *
269
+ * ## What this does instead
270
+ *
271
+ * `scrollOffset` is the transcript row drawn at the top of the screen, and
272
+ * `null` means "follow the tail", which is the normal live behaviour and the
273
+ * path everything else in this file was written for. The moment it is a
274
+ * number the TUI switches to the alternate screen and paints a window of the
275
+ * buffer itself: a fixed grid, addressed row by row, with no scrollback for
276
+ * anything to fight over. New output still arrives and still lands in the
277
+ * buffer — it just does not move the window, which is the whole point. The
278
+ * indicator on the last row says how far down the transcript the window is,
279
+ * because a view that cannot move on its own needs to say where it stopped.
280
+ *
281
+ * Going back to live leaves the alternate screen, which restores the normal
282
+ * screen *and its scrollback* exactly as they were, and the next frame is an
283
+ * ordinary differential one that writes only what arrived while the reader
284
+ * was away — see `scrollToLive` for what has to be true for that to be safe.
285
+ * Not a clear-and-replay: on a long session that is a visible flash, a burst
286
+ * of output, and the loss of the scrollback that had just been handed back.
287
+ */
288
+ private scrollOffset;
289
+ /** Transcript length measured by the last pinned paint; what clamping uses. */
290
+ private scrollTotalLines;
291
+ private scrollStatusFormatter;
292
+ /** The running search: its query, the rows it matched, and where in them. */
293
+ private scrollSearch;
294
+ /**
295
+ * Whether the view may pin right now.
296
+ *
297
+ * The wheel is answered wherever it is turned, including with a picker on
298
+ * screen — and a picker that lost its arrow keys to a pinned view it did not
299
+ * know about would be far worse than a wheel that did nothing. The app sets
300
+ * this because only the app knows which of its surfaces is asking a question.
301
+ * Unset means always.
302
+ */
303
+ canPinScroll?: () => boolean;
172
304
  private focusOrderCounter;
173
305
  private overlayStack;
174
306
  constructor(terminal: Terminal, showHardwareCursor?: boolean);
175
307
  get fullRedraws(): number;
308
+ /** True while the view is pinned rather than following the tail. */
309
+ get scrollPinned(): boolean;
310
+ /** Where the pinned window sits, or null while live. */
311
+ getScrollPosition(): {
312
+ top: number;
313
+ total: number;
314
+ viewHeight: number;
315
+ } | null;
316
+ /** Let the app paint the indicator in its own theme. */
317
+ setScrollStatusFormatter(formatter: ScrollStatusFormatter): void;
318
+ /**
319
+ * The screen rows a pinned window shows, the last one being the indicator.
320
+ *
321
+ * The indicator is not optional: a pinned view looks exactly like a live one
322
+ * that has gone quiet, and a reader who cannot tell the two apart will wait
323
+ * for output that is arriving perfectly well just out of sight.
324
+ */
325
+ private scrollViewHeight;
326
+ /** Rows available to scroll through — the live buffer while live, the
327
+ * measured one while pinned. */
328
+ private transcriptLength;
329
+ /**
330
+ * Move the view by `delta` rows; negative is towards the start.
331
+ *
332
+ * Returns whether anything moved, so a caller can let the key fall through
333
+ * to whatever else wants it when there is nothing to scroll.
334
+ */
335
+ scrollByLines(delta: number): boolean;
336
+ /**
337
+ * Move by pages, keeping two rows of overlap.
338
+ *
339
+ * A page that moves a full screen leaves nothing in common between before
340
+ * and after, and the reader has to find their place again on every press.
341
+ * The two kept rows are what makes the jump readable.
342
+ */
343
+ scrollByPages(delta: number): boolean;
344
+ /** Pin the view to the very start of the transcript. */
345
+ scrollToTop(): boolean;
346
+ /** Release the pin and follow the tail again. */
347
+ scrollToLive(): boolean;
348
+ /**
349
+ * Find rows containing `query`, and pin the view to the nearest one above.
350
+ *
351
+ * Searching *backwards* first is the `ctrl+r` convention and it is the right
352
+ * one here: what you are looking for in a session is nearly always behind
353
+ * you, and the most recent occurrence is nearly always the one you meant.
354
+ *
355
+ * Matching is over the visible text, so it finds what the screen shows
356
+ * rather than the escape sequences underneath it — a query containing a
357
+ * colour code is not something anyone ever means.
358
+ *
359
+ * Returns how many rows matched.
360
+ */
361
+ setScrollSearch(query: string, options?: {
362
+ typing?: boolean;
363
+ }): number;
364
+ /**
365
+ * Step to the next match, `-1` being further back through the session.
366
+ *
367
+ * Wraps, because a search that stops dead at the last match makes you
368
+ * retype it to get back to the first.
369
+ */
370
+ scrollSearchStep(direction: 1 | -1): boolean;
371
+ /** Stop typing the query but keep the matches, so n/N can step them. */
372
+ commitScrollSearch(): void;
373
+ /** Drop the search, leaving the view where it is. */
374
+ clearScrollSearch(): void;
375
+ get scrollSearchActive(): boolean;
376
+ /** The query being searched for, or "" when there is no search. */
377
+ get scrollSearchQuery(): string;
378
+ private scrollSearchStatus;
379
+ /**
380
+ * Rows whose visible text contains `query`, case-insensitively.
381
+ *
382
+ * One pass over the buffer, run when the query changes rather than per
383
+ * frame. The results are re-measured if the transcript has grown since —
384
+ * rare while someone is reading, and wrong in a way people notice if skipped.
385
+ */
386
+ private findScrollMatches;
387
+ /** Re-run the search if the buffer grew under it. */
388
+ private refreshScrollSearch;
389
+ /**
390
+ * Mark the query where it appears in a row about to be painted.
391
+ *
392
+ * Done at paint time, over the handful of rows on screen, rather than stored
393
+ * per match — highlighting the whole buffer to show a screenful would be the
394
+ * same work multiplied by the session's length.
395
+ *
396
+ * The row is sliced by display column so the styling already in it survives:
397
+ * a match inside a coloured span keeps its colour and gains the marker.
398
+ */
399
+ private highlightScrollMatches;
400
+ private setScrollOffset;
176
401
  getShowHardwareCursor(): boolean;
177
402
  setShowHardwareCursor(enabled: boolean): void;
178
403
  getClearOnShrink(): boolean;
@@ -182,6 +407,28 @@ export declare class TUI extends Container {
182
407
  * When false, empty rows remain (reduces redraws on slower terminals).
183
408
  */
184
409
  setClearOnShrink(enabled: boolean): void;
410
+ /** The component keystrokes are currently going to. */
411
+ get focused(): Component | null;
412
+ /**
413
+ * The root's own child offsets, which the flat cache already tracks.
414
+ *
415
+ * The base implementation reads `Container.renderMemo`, which the root does
416
+ * not keep — it has `flatCache` instead, holding exactly this. Falling
417
+ * through to the base would quietly return undefined forever.
418
+ */
419
+ childRowOffsets(width: number): number[] | undefined;
420
+ /**
421
+ * Pin the view so `row` is on screen, without demanding it be at the top.
422
+ *
423
+ * A jump that always parks its target on the first row throws away whatever
424
+ * led up to it, and what led up to a message is most of what makes it
425
+ * readable. A row already comfortably in view is left where it is, so
426
+ * stepping through nearby landmarks does not make the screen lurch for each
427
+ * one.
428
+ */
429
+ scrollToRow(row: number, options?: {
430
+ context?: number;
431
+ }): boolean;
185
432
  setFocus(component: Component | null): void;
186
433
  /**
187
434
  * Show an overlay component with configurable positioning and sizing.
@@ -205,6 +452,24 @@ export declare class TUI extends Container {
205
452
  requestRender(force?: boolean): void;
206
453
  private scheduleRender;
207
454
  private handleInput;
455
+ /**
456
+ * Act on every mouse report in `data` and return what is left of it.
457
+ *
458
+ * Returns null when the chunk was nothing but reports. Reports arrive
459
+ * coalesced — a flick of the wheel delivers a run of them in one read, and a
460
+ * keystroke pressed during the flick rides along behind — so they are peeled
461
+ * off one at a time instead of the chunk being classified as a whole.
462
+ */
463
+ private consumeMouseReports;
464
+ /**
465
+ * What the mouse does.
466
+ *
467
+ * Only the wheel is acted on. Clicks are swallowed rather than handled:
468
+ * reporting is on for the wheel's sake, and a click that fell through to the
469
+ * focused component would arrive as the raw report text in whatever field
470
+ * has focus.
471
+ */
472
+ private handleMouseEvent;
208
473
  /** Run a requested render now, bypassing the coalescing delay. Used for
209
474
  * input-driven frames where echo latency matters more than batching. */
210
475
  private expediteRender;
@@ -256,6 +521,27 @@ export declare class TUI extends Container {
256
521
  * or the child list changed.
257
522
  */
258
523
  render(width: number): string[];
524
+ /**
525
+ * Paint the pinned window onto the alternate screen.
526
+ *
527
+ * Deliberately not differential. The alternate screen is `rows` tall and
528
+ * nothing else writes to it, so a whole frame is at most a screenful of
529
+ * cells inside one synchronized-output pair — cheaper to emit than the
530
+ * bookkeeping a diff would need, and with nothing to get out of step with.
531
+ * The differential renderer's state is left exactly as the last live frame
532
+ * left it, because `scrollToLive` throws it away rather than resuming from it.
533
+ */
534
+ private renderScrollView;
535
+ /**
536
+ * One transcript row, ready for the pinned window.
537
+ *
538
+ * Images are named rather than drawn. A kitty or iTerm image is placed by
539
+ * the cursor and sized in pixels, so the same escape replayed at a different
540
+ * screen row lands somewhere the window did not ask for and survives the
541
+ * frame that was supposed to replace it — a smear across the view that no
542
+ * later repaint can clear.
543
+ */
544
+ private emitScrollLine;
259
545
  private doRender;
260
546
  /**
261
547
  * Build the escape sequence that parks the hardware cursor for this frame.