@prometheus-ai/tui 0.5.3 → 0.5.8

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 (55) hide show
  1. package/dist/types/autocomplete.d.ts +3 -1
  2. package/dist/types/components/box.d.ts +1 -1
  3. package/dist/types/components/editor.d.ts +35 -2
  4. package/dist/types/components/image.d.ts +22 -3
  5. package/dist/types/components/input.d.ts +6 -1
  6. package/dist/types/components/loader.d.ts +9 -2
  7. package/dist/types/components/markdown.d.ts +3 -1
  8. package/dist/types/components/scroll-view.d.ts +23 -1
  9. package/dist/types/components/select-list.d.ts +19 -1
  10. package/dist/types/components/settings-list.d.ts +87 -7
  11. package/dist/types/components/spacer.d.ts +1 -1
  12. package/dist/types/components/tab-bar.d.ts +37 -4
  13. package/dist/types/components/text.d.ts +2 -2
  14. package/dist/types/components/truncated-text.d.ts +1 -1
  15. package/dist/types/fuzzy.d.ts +10 -1
  16. package/dist/types/index.d.ts +1 -0
  17. package/dist/types/keybindings.d.ts +5 -3
  18. package/dist/types/keys.d.ts +1 -1
  19. package/dist/types/kill-ring.d.ts +0 -7
  20. package/dist/types/kitty-graphics.d.ts +16 -31
  21. package/dist/types/loop-watchdog.d.ts +39 -0
  22. package/dist/types/mouse.d.ts +41 -0
  23. package/dist/types/stdin-buffer.d.ts +17 -0
  24. package/dist/types/terminal-capabilities.d.ts +74 -18
  25. package/dist/types/terminal.d.ts +34 -36
  26. package/dist/types/tui.d.ts +191 -79
  27. package/dist/types/utils.d.ts +5 -2
  28. package/package.json +4 -4
  29. package/src/autocomplete.ts +79 -65
  30. package/src/components/box.ts +43 -63
  31. package/src/components/editor.ts +471 -136
  32. package/src/components/image.ts +85 -9
  33. package/src/components/input.ts +12 -3
  34. package/src/components/loader.ts +35 -21
  35. package/src/components/markdown.ts +174 -53
  36. package/src/components/scroll-view.ts +63 -2
  37. package/src/components/select-list.ts +233 -38
  38. package/src/components/settings-list.ts +626 -64
  39. package/src/components/spacer.ts +9 -5
  40. package/src/components/tab-bar.ts +153 -28
  41. package/src/components/text.ts +6 -2
  42. package/src/components/truncated-text.ts +10 -2
  43. package/src/fuzzy.ts +214 -59
  44. package/src/index.ts +3 -1
  45. package/src/keybindings.ts +72 -14
  46. package/src/keys.ts +1 -1
  47. package/src/kill-ring.ts +5 -0
  48. package/src/kitty-graphics.ts +2 -101
  49. package/src/loop-watchdog.ts +106 -0
  50. package/src/mouse.ts +55 -0
  51. package/src/stdin-buffer.ts +291 -81
  52. package/src/terminal-capabilities.ts +206 -168
  53. package/src/terminal.ts +367 -110
  54. package/src/tui.ts +2102 -1729
  55. package/src/utils.ts +92 -60
@@ -2,7 +2,9 @@ import type { Component } from "../tui";
2
2
  import { applyBackgroundToLine, padding, visibleWidth } from "../utils";
3
3
 
4
4
  type Cache = {
5
- key: bigint | number;
5
+ width: number;
6
+ bgSample: string | undefined;
7
+ childLines: (readonly string[])[];
6
8
  result: string[];
7
9
  };
8
10
 
@@ -63,24 +65,6 @@ export class Box implements Component {
63
65
  this.#cached = undefined;
64
66
  }
65
67
 
66
- static #tmp = new Uint32Array(2);
67
- #computeCacheKey(width: number, childLines: string[], bgSample: string | undefined): bigint | number {
68
- Box.#tmp[0] = width;
69
- Box.#tmp[1] = childLines.length;
70
- let h = Bun.hash(Box.#tmp);
71
- for (const line of childLines) {
72
- h = Bun.hash(line, h);
73
- }
74
- if (bgSample) {
75
- h = Bun.hash(bgSample, h);
76
- }
77
- return h;
78
- }
79
-
80
- #matchCache(cacheKey: bigint | number): boolean {
81
- return this.#cached?.key === cacheKey;
82
- }
83
-
84
68
  invalidate(): void {
85
69
  this.#invalidateCache();
86
70
  for (const child of this.children) {
@@ -88,58 +72,54 @@ export class Box implements Component {
88
72
  }
89
73
  }
90
74
 
91
- render(width: number): string[] {
92
- if (this.children.length === 0) {
93
- return [];
94
- }
95
-
75
+ render(width: number): readonly string[] {
76
+ const children = this.children;
77
+ const count = children.length;
96
78
  const contentWidth = Math.max(1, width - this.#paddingX * 2);
97
- const leftPad = padding(this.#paddingX);
98
-
99
- // Render all children
100
- const childLines: string[] = [];
101
- for (const child of this.children) {
102
- const lines = child.render(contentWidth);
103
- for (const line of lines) {
104
- childLines.push(leftPad + line);
105
- }
106
- }
107
-
108
- if (childLines.length === 0) {
109
- return [];
110
- }
111
-
112
- // Check if bgFn output changed by sampling
79
+ // bgFn output can change without the function reference changing (theme
80
+ // mutation); sample it so a silent palette swap still misses the cache.
113
81
  const bgSample = this.#bgFn ? this.#bgFn("test") : undefined;
114
82
 
115
- const cacheKey = this.#computeCacheKey(width, childLines, bgSample);
116
-
117
- // Check cache validity
118
- if (this.#matchCache(cacheKey)) {
119
- return this.#cached!.result;
83
+ // Render every child every frame (renders may carry side effects); the
84
+ // memo only skips re-deriving the padded/background rows. Per the
85
+ // Component render contract, identical child array references prove the
86
+ // content is unchanged.
87
+ const cached = this.#cached;
88
+ let unchanged =
89
+ cached !== undefined &&
90
+ cached.width === width &&
91
+ cached.bgSample === bgSample &&
92
+ cached.childLines.length === count;
93
+ const childLines: (readonly string[])[] = new Array(count);
94
+ let contentRows = 0;
95
+ for (let i = 0; i < count; i++) {
96
+ const lines = children[i]!.render(contentWidth);
97
+ childLines[i] = lines;
98
+ contentRows += lines.length;
99
+ if (unchanged && cached!.childLines[i] !== lines) unchanged = false;
120
100
  }
101
+ if (unchanged) return cached!.result;
121
102
 
122
- // Apply background and padding
123
103
  const result: string[] = [];
124
-
125
- // Top padding
126
- for (let i = 0; i < this.#paddingY; i++) {
127
- result.push(this.#applyBg("", width));
128
- }
129
-
130
- // Content
131
- for (const line of childLines) {
132
- result.push(this.#applyBg(line, width));
133
- }
134
-
135
- // Bottom padding
136
- for (let i = 0; i < this.#paddingY; i++) {
137
- result.push(this.#applyBg("", width));
104
+ if (contentRows > 0) {
105
+ const leftPad = padding(this.#paddingX);
106
+ // Top padding
107
+ for (let i = 0; i < this.#paddingY; i++) {
108
+ result.push(this.#applyBg("", width));
109
+ }
110
+ // Content
111
+ for (const lines of childLines) {
112
+ for (const line of lines) {
113
+ result.push(this.#applyBg(leftPad + line, width));
114
+ }
115
+ }
116
+ // Bottom padding
117
+ for (let i = 0; i < this.#paddingY; i++) {
118
+ result.push(this.#applyBg("", width));
119
+ }
138
120
  }
139
121
 
140
- // Update cache
141
- this.#cached = { key: cacheKey, result };
142
-
122
+ this.#cached = { width, bgSample, childLines, result };
143
123
  return result;
144
124
  }
145
125