@elizaos/tui 2.0.0-alpha.10

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 (140) hide show
  1. package/README.md +761 -0
  2. package/dist/autocomplete.d.ts +48 -0
  3. package/dist/autocomplete.d.ts.map +1 -0
  4. package/dist/autocomplete.js +555 -0
  5. package/dist/components/box.d.ts +22 -0
  6. package/dist/components/box.d.ts.map +1 -0
  7. package/dist/components/box.js +103 -0
  8. package/dist/components/cancellable-loader.d.ts +22 -0
  9. package/dist/components/cancellable-loader.d.ts.map +1 -0
  10. package/dist/components/cancellable-loader.js +34 -0
  11. package/dist/components/editor/history.d.ts +38 -0
  12. package/dist/components/editor/history.d.ts.map +1 -0
  13. package/dist/components/editor/history.js +76 -0
  14. package/dist/components/editor/index.d.ts +18 -0
  15. package/dist/components/editor/index.d.ts.map +1 -0
  16. package/dist/components/editor/index.js +21 -0
  17. package/dist/components/editor/kill-ring.d.ts +41 -0
  18. package/dist/components/editor/kill-ring.d.ts.map +1 -0
  19. package/dist/components/editor/kill-ring.js +81 -0
  20. package/dist/components/editor/layout.d.ts +40 -0
  21. package/dist/components/editor/layout.d.ts.map +1 -0
  22. package/dist/components/editor/layout.js +205 -0
  23. package/dist/components/editor/types.d.ts +68 -0
  24. package/dist/components/editor/types.d.ts.map +1 -0
  25. package/dist/components/editor/types.js +4 -0
  26. package/dist/components/editor/undo.d.ts +46 -0
  27. package/dist/components/editor/undo.d.ts.map +1 -0
  28. package/dist/components/editor/undo.js +58 -0
  29. package/dist/components/editor.d.ts +196 -0
  30. package/dist/components/editor.d.ts.map +1 -0
  31. package/dist/components/editor.js +1707 -0
  32. package/dist/components/image.d.ts +28 -0
  33. package/dist/components/image.d.ts.map +1 -0
  34. package/dist/components/image.js +68 -0
  35. package/dist/components/input.d.ts +19 -0
  36. package/dist/components/input.d.ts.map +1 -0
  37. package/dist/components/input.js +195 -0
  38. package/dist/components/loader.d.ts +21 -0
  39. package/dist/components/loader.d.ts.map +1 -0
  40. package/dist/components/loader.js +49 -0
  41. package/dist/components/markdown/index.d.ts +13 -0
  42. package/dist/components/markdown/index.d.ts.map +1 -0
  43. package/dist/components/markdown/index.js +9 -0
  44. package/dist/components/markdown/inline-renderer.d.ts +22 -0
  45. package/dist/components/markdown/inline-renderer.d.ts.map +1 -0
  46. package/dist/components/markdown/inline-renderer.js +88 -0
  47. package/dist/components/markdown/list-renderer.d.ts +33 -0
  48. package/dist/components/markdown/list-renderer.d.ts.map +1 -0
  49. package/dist/components/markdown/list-renderer.js +110 -0
  50. package/dist/components/markdown/table-renderer.d.ts +43 -0
  51. package/dist/components/markdown/table-renderer.d.ts.map +1 -0
  52. package/dist/components/markdown/table-renderer.js +184 -0
  53. package/dist/components/markdown/types.d.ts +57 -0
  54. package/dist/components/markdown/types.d.ts.map +1 -0
  55. package/dist/components/markdown/types.js +13 -0
  56. package/dist/components/markdown.d.ts +44 -0
  57. package/dist/components/markdown.d.ts.map +1 -0
  58. package/dist/components/markdown.js +319 -0
  59. package/dist/components/progress-bar.d.ts +67 -0
  60. package/dist/components/progress-bar.d.ts.map +1 -0
  61. package/dist/components/progress-bar.js +124 -0
  62. package/dist/components/select-list.d.ts +32 -0
  63. package/dist/components/select-list.d.ts.map +1 -0
  64. package/dist/components/select-list.js +151 -0
  65. package/dist/components/settings-list.d.ts +50 -0
  66. package/dist/components/settings-list.d.ts.map +1 -0
  67. package/dist/components/settings-list.js +184 -0
  68. package/dist/components/spacer.d.ts +12 -0
  69. package/dist/components/spacer.d.ts.map +1 -0
  70. package/dist/components/spacer.js +22 -0
  71. package/dist/components/text.d.ts +19 -0
  72. package/dist/components/text.d.ts.map +1 -0
  73. package/dist/components/text.js +88 -0
  74. package/dist/components/toast.d.ts +73 -0
  75. package/dist/components/toast.d.ts.map +1 -0
  76. package/dist/components/toast.js +119 -0
  77. package/dist/components/truncated-text.d.ts +13 -0
  78. package/dist/components/truncated-text.d.ts.map +1 -0
  79. package/dist/components/truncated-text.js +50 -0
  80. package/dist/constants.d.ts +97 -0
  81. package/dist/constants.d.ts.map +1 -0
  82. package/dist/constants.js +126 -0
  83. package/dist/core/container.d.ts +32 -0
  84. package/dist/core/container.d.ts.map +1 -0
  85. package/dist/core/container.js +49 -0
  86. package/dist/core/index.d.ts +9 -0
  87. package/dist/core/index.d.ts.map +1 -0
  88. package/dist/core/index.js +10 -0
  89. package/dist/core/overlay.d.ts +44 -0
  90. package/dist/core/overlay.d.ts.map +1 -0
  91. package/dist/core/overlay.js +171 -0
  92. package/dist/core/types.d.ts +116 -0
  93. package/dist/core/types.d.ts.map +1 -0
  94. package/dist/core/types.js +14 -0
  95. package/dist/editor-component.d.ts +37 -0
  96. package/dist/editor-component.d.ts.map +1 -0
  97. package/dist/editor-component.js +1 -0
  98. package/dist/fuzzy.d.ts +16 -0
  99. package/dist/fuzzy.d.ts.map +1 -0
  100. package/dist/fuzzy.js +108 -0
  101. package/dist/index.d.ts +29 -0
  102. package/dist/index.d.ts.map +1 -0
  103. package/dist/index.js +59 -0
  104. package/dist/keybindings.d.ts +39 -0
  105. package/dist/keybindings.d.ts.map +1 -0
  106. package/dist/keybindings.js +113 -0
  107. package/dist/keys.d.ts +153 -0
  108. package/dist/keys.d.ts.map +1 -0
  109. package/dist/keys.js +951 -0
  110. package/dist/stdin-buffer.d.ts +48 -0
  111. package/dist/stdin-buffer.d.ts.map +1 -0
  112. package/dist/stdin-buffer.js +316 -0
  113. package/dist/terminal-image.d.ts +68 -0
  114. package/dist/terminal-image.d.ts.map +1 -0
  115. package/dist/terminal-image.js +287 -0
  116. package/dist/terminal.d.ts +71 -0
  117. package/dist/terminal.d.ts.map +1 -0
  118. package/dist/terminal.js +216 -0
  119. package/dist/themes/index.d.ts +103 -0
  120. package/dist/themes/index.d.ts.map +1 -0
  121. package/dist/themes/index.js +161 -0
  122. package/dist/tui.d.ts +90 -0
  123. package/dist/tui.d.ts.map +1 -0
  124. package/dist/tui.js +745 -0
  125. package/dist/types/marked-tokens.d.ts +57 -0
  126. package/dist/types/marked-tokens.d.ts.map +1 -0
  127. package/dist/types/marked-tokens.js +17 -0
  128. package/dist/utils/cursor-movement.d.ts +127 -0
  129. package/dist/utils/cursor-movement.d.ts.map +1 -0
  130. package/dist/utils/cursor-movement.js +251 -0
  131. package/dist/utils/index.d.ts +6 -0
  132. package/dist/utils/index.d.ts.map +1 -0
  133. package/dist/utils/index.js +7 -0
  134. package/dist/utils/paste-handler.d.ts +86 -0
  135. package/dist/utils/paste-handler.d.ts.map +1 -0
  136. package/dist/utils/paste-handler.js +121 -0
  137. package/dist/utils.d.ts +75 -0
  138. package/dist/utils.d.ts.map +1 -0
  139. package/dist/utils.js +796 -0
  140. package/package.json +53 -0
@@ -0,0 +1,151 @@
1
+ import { getEditorKeybindings } from "../keybindings.js";
2
+ import { truncateToWidth } from "../utils.js";
3
+ const normalizeToSingleLine = (text) => text.replace(/[\r\n]+/g, " ").trim();
4
+ export class SelectList {
5
+ items = [];
6
+ filteredItems = [];
7
+ selectedIndex = 0;
8
+ maxVisible = 5;
9
+ theme;
10
+ onSelect;
11
+ onCancel;
12
+ onSelectionChange;
13
+ constructor(items, maxVisible, theme) {
14
+ this.items = items;
15
+ this.filteredItems = items;
16
+ this.maxVisible = maxVisible;
17
+ this.theme = theme;
18
+ }
19
+ setFilter(filter) {
20
+ this.filteredItems = this.items.filter((item) => item.value.toLowerCase().startsWith(filter.toLowerCase()));
21
+ // Reset selection when filter changes
22
+ this.selectedIndex = 0;
23
+ }
24
+ setSelectedIndex(index) {
25
+ this.selectedIndex = Math.max(0, Math.min(index, this.filteredItems.length - 1));
26
+ }
27
+ invalidate() {
28
+ // No cached state to invalidate currently
29
+ }
30
+ render(width) {
31
+ const lines = [];
32
+ // If no items match filter, show message
33
+ if (this.filteredItems.length === 0) {
34
+ lines.push(this.theme.noMatch(" No matching commands"));
35
+ return lines;
36
+ }
37
+ // Calculate visible range with scrolling
38
+ const startIndex = Math.max(0, Math.min(this.selectedIndex - Math.floor(this.maxVisible / 2), this.filteredItems.length - this.maxVisible));
39
+ const endIndex = Math.min(startIndex + this.maxVisible, this.filteredItems.length);
40
+ // Render visible items
41
+ for (let i = startIndex; i < endIndex; i++) {
42
+ const item = this.filteredItems[i];
43
+ if (!item)
44
+ continue;
45
+ const isSelected = i === this.selectedIndex;
46
+ const descriptionSingleLine = item.description ? normalizeToSingleLine(item.description) : undefined;
47
+ let line = "";
48
+ if (isSelected) {
49
+ // Use arrow indicator for selection - entire line uses selectedText color
50
+ const prefixWidth = 2; // "→ " is 2 characters visually
51
+ const displayValue = item.label || item.value;
52
+ if (descriptionSingleLine && width > 40) {
53
+ // Calculate how much space we have for value + description
54
+ const maxValueWidth = Math.min(30, width - prefixWidth - 4);
55
+ const truncatedValue = truncateToWidth(displayValue, maxValueWidth, "");
56
+ const spacing = " ".repeat(Math.max(1, 32 - truncatedValue.length));
57
+ // Calculate remaining space for description using visible widths
58
+ const descriptionStart = prefixWidth + truncatedValue.length + spacing.length;
59
+ const remainingWidth = width - descriptionStart - 2; // -2 for safety
60
+ if (remainingWidth > 10) {
61
+ const truncatedDesc = truncateToWidth(descriptionSingleLine, remainingWidth, "");
62
+ // Apply selectedText to entire line content
63
+ line = this.theme.selectedText(`→ ${truncatedValue}${spacing}${truncatedDesc}`);
64
+ }
65
+ else {
66
+ // Not enough space for description
67
+ const maxWidth = width - prefixWidth - 2;
68
+ line = this.theme.selectedText(`→ ${truncateToWidth(displayValue, maxWidth, "")}`);
69
+ }
70
+ }
71
+ else {
72
+ // No description or not enough width
73
+ const maxWidth = width - prefixWidth - 2;
74
+ line = this.theme.selectedText(`→ ${truncateToWidth(displayValue, maxWidth, "")}`);
75
+ }
76
+ }
77
+ else {
78
+ const displayValue = item.label || item.value;
79
+ const prefix = " ";
80
+ if (descriptionSingleLine && width > 40) {
81
+ // Calculate how much space we have for value + description
82
+ const maxValueWidth = Math.min(30, width - prefix.length - 4);
83
+ const truncatedValue = truncateToWidth(displayValue, maxValueWidth, "");
84
+ const spacing = " ".repeat(Math.max(1, 32 - truncatedValue.length));
85
+ // Calculate remaining space for description
86
+ const descriptionStart = prefix.length + truncatedValue.length + spacing.length;
87
+ const remainingWidth = width - descriptionStart - 2; // -2 for safety
88
+ if (remainingWidth > 10) {
89
+ const truncatedDesc = truncateToWidth(descriptionSingleLine, remainingWidth, "");
90
+ const descText = this.theme.description(spacing + truncatedDesc);
91
+ line = prefix + truncatedValue + descText;
92
+ }
93
+ else {
94
+ // Not enough space for description
95
+ const maxWidth = width - prefix.length - 2;
96
+ line = prefix + truncateToWidth(displayValue, maxWidth, "");
97
+ }
98
+ }
99
+ else {
100
+ // No description or not enough width
101
+ const maxWidth = width - prefix.length - 2;
102
+ line = prefix + truncateToWidth(displayValue, maxWidth, "");
103
+ }
104
+ }
105
+ lines.push(line);
106
+ }
107
+ // Add scroll indicators if needed
108
+ if (startIndex > 0 || endIndex < this.filteredItems.length) {
109
+ const scrollText = ` (${this.selectedIndex + 1}/${this.filteredItems.length})`;
110
+ // Truncate if too long for terminal
111
+ lines.push(this.theme.scrollInfo(truncateToWidth(scrollText, width - 2, "")));
112
+ }
113
+ return lines;
114
+ }
115
+ handleInput(keyData) {
116
+ const kb = getEditorKeybindings();
117
+ // Up arrow - wrap to bottom when at top
118
+ if (kb.matches(keyData, "selectUp")) {
119
+ this.selectedIndex = this.selectedIndex === 0 ? this.filteredItems.length - 1 : this.selectedIndex - 1;
120
+ this.notifySelectionChange();
121
+ }
122
+ // Down arrow - wrap to top when at bottom
123
+ else if (kb.matches(keyData, "selectDown")) {
124
+ this.selectedIndex = this.selectedIndex === this.filteredItems.length - 1 ? 0 : this.selectedIndex + 1;
125
+ this.notifySelectionChange();
126
+ }
127
+ // Enter
128
+ else if (kb.matches(keyData, "selectConfirm")) {
129
+ const selectedItem = this.filteredItems[this.selectedIndex];
130
+ if (selectedItem && this.onSelect) {
131
+ this.onSelect(selectedItem);
132
+ }
133
+ }
134
+ // Escape or Ctrl+C
135
+ else if (kb.matches(keyData, "selectCancel")) {
136
+ if (this.onCancel) {
137
+ this.onCancel();
138
+ }
139
+ }
140
+ }
141
+ notifySelectionChange() {
142
+ const selectedItem = this.filteredItems[this.selectedIndex];
143
+ if (selectedItem && this.onSelectionChange) {
144
+ this.onSelectionChange(selectedItem);
145
+ }
146
+ }
147
+ getSelectedItem() {
148
+ const item = this.filteredItems[this.selectedIndex];
149
+ return item || null;
150
+ }
151
+ }
@@ -0,0 +1,50 @@
1
+ import type { Component } from "../tui.js";
2
+ export interface SettingItem {
3
+ /** Unique identifier for this setting */
4
+ id: string;
5
+ /** Display label (left side) */
6
+ label: string;
7
+ /** Optional description shown when selected */
8
+ description?: string;
9
+ /** Current value to display (right side) */
10
+ currentValue: string;
11
+ /** If provided, Enter/Space cycles through these values */
12
+ values?: string[];
13
+ /** If provided, Enter opens this submenu. Receives current value and done callback. */
14
+ submenu?: (currentValue: string, done: (selectedValue?: string) => void) => Component;
15
+ }
16
+ export interface SettingsListTheme {
17
+ label: (text: string, selected: boolean) => string;
18
+ value: (text: string, selected: boolean) => string;
19
+ description: (text: string) => string;
20
+ cursor: string;
21
+ hint: (text: string) => string;
22
+ }
23
+ export interface SettingsListOptions {
24
+ enableSearch?: boolean;
25
+ }
26
+ export declare class SettingsList implements Component {
27
+ private items;
28
+ private filteredItems;
29
+ private theme;
30
+ private selectedIndex;
31
+ private maxVisible;
32
+ private onChange;
33
+ private onCancel;
34
+ private searchInput?;
35
+ private searchEnabled;
36
+ private submenuComponent;
37
+ private submenuItemIndex;
38
+ constructor(items: SettingItem[], maxVisible: number, theme: SettingsListTheme, onChange: (id: string, newValue: string) => void, onCancel: () => void, options?: SettingsListOptions);
39
+ /** Update an item's currentValue */
40
+ updateValue(id: string, newValue: string): void;
41
+ invalidate(): void;
42
+ render(width: number): string[];
43
+ private renderMainList;
44
+ handleInput(data: string): void;
45
+ private activateItem;
46
+ private closeSubmenu;
47
+ private applyFilter;
48
+ private addHintLine;
49
+ }
50
+ //# sourceMappingURL=settings-list.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settings-list.d.ts","sourceRoot":"","sources":["../../src/components/settings-list.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAI3C,MAAM,WAAW,WAAW;IAC3B,yCAAyC;IACzC,EAAE,EAAE,MAAM,CAAC;IACX,gCAAgC;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,+CAA+C;IAC/C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,4CAA4C;IAC5C,YAAY,EAAE,MAAM,CAAC;IACrB,2DAA2D;IAC3D,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,uFAAuF;IACvF,OAAO,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,aAAa,CAAC,EAAE,MAAM,KAAK,IAAI,KAAK,SAAS,CAAC;CACtF;AAED,MAAM,WAAW,iBAAiB;IACjC,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,KAAK,MAAM,CAAC;IACnD,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,KAAK,MAAM,CAAC;IACnD,WAAW,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;CAC/B;AAED,MAAM,WAAW,mBAAmB;IACnC,YAAY,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,qBAAa,YAAa,YAAW,SAAS;IAC7C,OAAO,CAAC,KAAK,CAAgB;IAC7B,OAAO,CAAC,aAAa,CAAgB;IACrC,OAAO,CAAC,KAAK,CAAoB;IACjC,OAAO,CAAC,aAAa,CAAK;IAC1B,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,QAAQ,CAAyC;IACzD,OAAO,CAAC,QAAQ,CAAa;IAC7B,OAAO,CAAC,WAAW,CAAC,CAAQ;IAC5B,OAAO,CAAC,aAAa,CAAU;IAG/B,OAAO,CAAC,gBAAgB,CAA0B;IAClD,OAAO,CAAC,gBAAgB,CAAuB;gBAG9C,KAAK,EAAE,WAAW,EAAE,EACpB,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,iBAAiB,EACxB,QAAQ,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,IAAI,EAChD,QAAQ,EAAE,MAAM,IAAI,EACpB,OAAO,GAAE,mBAAwB;IAclC,oCAAoC;IACpC,WAAW,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI;IAO/C,UAAU,IAAI,IAAI;IAIlB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE;IAS/B,OAAO,CAAC,cAAc;IA8EtB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IA+B/B,OAAO,CAAC,YAAY;IAwBpB,OAAO,CAAC,YAAY;IASpB,OAAO,CAAC,WAAW;IAKnB,OAAO,CAAC,WAAW;CAanB"}
@@ -0,0 +1,184 @@
1
+ import { fuzzyFilter } from "../fuzzy.js";
2
+ import { getEditorKeybindings } from "../keybindings.js";
3
+ import { truncateToWidth, visibleWidth, wrapTextWithAnsi } from "../utils.js";
4
+ import { Input } from "./input.js";
5
+ export class SettingsList {
6
+ items;
7
+ filteredItems;
8
+ theme;
9
+ selectedIndex = 0;
10
+ maxVisible;
11
+ onChange;
12
+ onCancel;
13
+ searchInput;
14
+ searchEnabled;
15
+ // Submenu state
16
+ submenuComponent = null;
17
+ submenuItemIndex = null;
18
+ constructor(items, maxVisible, theme, onChange, onCancel, options = {}) {
19
+ this.items = items;
20
+ this.filteredItems = items;
21
+ this.maxVisible = maxVisible;
22
+ this.theme = theme;
23
+ this.onChange = onChange;
24
+ this.onCancel = onCancel;
25
+ this.searchEnabled = options.enableSearch ?? false;
26
+ if (this.searchEnabled) {
27
+ this.searchInput = new Input();
28
+ }
29
+ }
30
+ /** Update an item's currentValue */
31
+ updateValue(id, newValue) {
32
+ const item = this.items.find((i) => i.id === id);
33
+ if (item) {
34
+ item.currentValue = newValue;
35
+ }
36
+ }
37
+ invalidate() {
38
+ this.submenuComponent?.invalidate?.();
39
+ }
40
+ render(width) {
41
+ // If submenu is active, render it instead
42
+ if (this.submenuComponent) {
43
+ return this.submenuComponent.render(width);
44
+ }
45
+ return this.renderMainList(width);
46
+ }
47
+ renderMainList(width) {
48
+ const lines = [];
49
+ if (this.searchEnabled && this.searchInput) {
50
+ lines.push(...this.searchInput.render(width));
51
+ lines.push("");
52
+ }
53
+ if (this.items.length === 0) {
54
+ lines.push(this.theme.hint(" No settings available"));
55
+ if (this.searchEnabled) {
56
+ this.addHintLine(lines, width);
57
+ }
58
+ return lines;
59
+ }
60
+ const displayItems = this.searchEnabled ? this.filteredItems : this.items;
61
+ if (displayItems.length === 0) {
62
+ lines.push(truncateToWidth(this.theme.hint(" No matching settings"), width));
63
+ this.addHintLine(lines, width);
64
+ return lines;
65
+ }
66
+ // Calculate visible range with scrolling
67
+ const startIndex = Math.max(0, Math.min(this.selectedIndex - Math.floor(this.maxVisible / 2), displayItems.length - this.maxVisible));
68
+ const endIndex = Math.min(startIndex + this.maxVisible, displayItems.length);
69
+ // Calculate max label width for alignment
70
+ const maxLabelWidth = Math.min(30, Math.max(...this.items.map((item) => visibleWidth(item.label))));
71
+ // Render visible items
72
+ for (let i = startIndex; i < endIndex; i++) {
73
+ const item = displayItems[i];
74
+ if (!item)
75
+ continue;
76
+ const isSelected = i === this.selectedIndex;
77
+ const prefix = isSelected ? this.theme.cursor : " ";
78
+ const prefixWidth = visibleWidth(prefix);
79
+ // Pad label to align values
80
+ const labelPadded = item.label + " ".repeat(Math.max(0, maxLabelWidth - visibleWidth(item.label)));
81
+ const labelText = this.theme.label(labelPadded, isSelected);
82
+ // Calculate space for value
83
+ const separator = " ";
84
+ const usedWidth = prefixWidth + maxLabelWidth + visibleWidth(separator);
85
+ const valueMaxWidth = width - usedWidth - 2;
86
+ const valueText = this.theme.value(truncateToWidth(item.currentValue, valueMaxWidth, ""), isSelected);
87
+ lines.push(truncateToWidth(prefix + labelText + separator + valueText, width));
88
+ }
89
+ // Add scroll indicator if needed
90
+ if (startIndex > 0 || endIndex < displayItems.length) {
91
+ const scrollText = ` (${this.selectedIndex + 1}/${displayItems.length})`;
92
+ lines.push(this.theme.hint(truncateToWidth(scrollText, width - 2, "")));
93
+ }
94
+ // Add description for selected item
95
+ const selectedItem = displayItems[this.selectedIndex];
96
+ if (selectedItem?.description) {
97
+ lines.push("");
98
+ const wrappedDesc = wrapTextWithAnsi(selectedItem.description, width - 4);
99
+ for (const line of wrappedDesc) {
100
+ lines.push(this.theme.description(` ${line}`));
101
+ }
102
+ }
103
+ // Add hint
104
+ this.addHintLine(lines, width);
105
+ return lines;
106
+ }
107
+ handleInput(data) {
108
+ // If submenu is active, delegate all input to it
109
+ // The submenu's onCancel (triggered by escape) will call done() which closes it
110
+ if (this.submenuComponent) {
111
+ this.submenuComponent.handleInput?.(data);
112
+ return;
113
+ }
114
+ // Main list input handling
115
+ const kb = getEditorKeybindings();
116
+ const displayItems = this.searchEnabled ? this.filteredItems : this.items;
117
+ if (kb.matches(data, "selectUp")) {
118
+ if (displayItems.length === 0)
119
+ return;
120
+ this.selectedIndex = this.selectedIndex === 0 ? displayItems.length - 1 : this.selectedIndex - 1;
121
+ }
122
+ else if (kb.matches(data, "selectDown")) {
123
+ if (displayItems.length === 0)
124
+ return;
125
+ this.selectedIndex = this.selectedIndex === displayItems.length - 1 ? 0 : this.selectedIndex + 1;
126
+ }
127
+ else if (kb.matches(data, "selectConfirm") || data === " ") {
128
+ this.activateItem();
129
+ }
130
+ else if (kb.matches(data, "selectCancel")) {
131
+ this.onCancel();
132
+ }
133
+ else if (this.searchEnabled && this.searchInput) {
134
+ const sanitized = data.replace(/ /g, "");
135
+ if (!sanitized) {
136
+ return;
137
+ }
138
+ this.searchInput.handleInput(sanitized);
139
+ this.applyFilter(this.searchInput.getValue());
140
+ }
141
+ }
142
+ activateItem() {
143
+ const item = this.searchEnabled ? this.filteredItems[this.selectedIndex] : this.items[this.selectedIndex];
144
+ if (!item)
145
+ return;
146
+ if (item.submenu) {
147
+ // Open submenu, passing current value so it can pre-select correctly
148
+ this.submenuItemIndex = this.selectedIndex;
149
+ this.submenuComponent = item.submenu(item.currentValue, (selectedValue) => {
150
+ if (selectedValue !== undefined) {
151
+ item.currentValue = selectedValue;
152
+ this.onChange(item.id, selectedValue);
153
+ }
154
+ this.closeSubmenu();
155
+ });
156
+ }
157
+ else if (item.values && item.values.length > 0) {
158
+ // Cycle through values
159
+ const currentIndex = item.values.indexOf(item.currentValue);
160
+ const nextIndex = (currentIndex + 1) % item.values.length;
161
+ const newValue = item.values[nextIndex];
162
+ item.currentValue = newValue;
163
+ this.onChange(item.id, newValue);
164
+ }
165
+ }
166
+ closeSubmenu() {
167
+ this.submenuComponent = null;
168
+ // Restore selection to the item that opened the submenu
169
+ if (this.submenuItemIndex !== null) {
170
+ this.selectedIndex = this.submenuItemIndex;
171
+ this.submenuItemIndex = null;
172
+ }
173
+ }
174
+ applyFilter(query) {
175
+ this.filteredItems = fuzzyFilter(this.items, query, (item) => item.label);
176
+ this.selectedIndex = 0;
177
+ }
178
+ addHintLine(lines, width) {
179
+ lines.push("");
180
+ lines.push(truncateToWidth(this.theme.hint(this.searchEnabled
181
+ ? " Type to search · Enter/Space to change · Esc to cancel"
182
+ : " Enter/Space to change · Esc to cancel"), width));
183
+ }
184
+ }
@@ -0,0 +1,12 @@
1
+ import type { Component } from "../tui.js";
2
+ /**
3
+ * Spacer component that renders empty lines
4
+ */
5
+ export declare class Spacer implements Component {
6
+ private lines;
7
+ constructor(lines?: number);
8
+ setLines(lines: number): void;
9
+ invalidate(): void;
10
+ render(_width: number): string[];
11
+ }
12
+ //# sourceMappingURL=spacer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spacer.d.ts","sourceRoot":"","sources":["../../src/components/spacer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAE3C;;GAEG;AACH,qBAAa,MAAO,YAAW,SAAS;IACvC,OAAO,CAAC,KAAK,CAAS;gBAEV,KAAK,GAAE,MAAU;IAI7B,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAI7B,UAAU,IAAI,IAAI;IAIlB,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE;CAOhC"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Spacer component that renders empty lines
3
+ */
4
+ export class Spacer {
5
+ lines;
6
+ constructor(lines = 1) {
7
+ this.lines = lines;
8
+ }
9
+ setLines(lines) {
10
+ this.lines = lines;
11
+ }
12
+ invalidate() {
13
+ // No cached state to invalidate currently
14
+ }
15
+ render(_width) {
16
+ const result = [];
17
+ for (let i = 0; i < this.lines; i++) {
18
+ result.push("");
19
+ }
20
+ return result;
21
+ }
22
+ }
@@ -0,0 +1,19 @@
1
+ import type { Component } from "../tui.js";
2
+ /**
3
+ * Text component - displays multi-line text with word wrapping
4
+ */
5
+ export declare class Text implements Component {
6
+ private text;
7
+ private paddingX;
8
+ private paddingY;
9
+ private customBgFn?;
10
+ private cachedText?;
11
+ private cachedWidth?;
12
+ private cachedLines?;
13
+ constructor(text?: string, paddingX?: number, paddingY?: number, customBgFn?: (text: string) => string);
14
+ setText(text: string): void;
15
+ setCustomBgFn(customBgFn?: (text: string) => string): void;
16
+ invalidate(): void;
17
+ render(width: number): string[];
18
+ }
19
+ //# sourceMappingURL=text.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../src/components/text.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAG3C;;GAEG;AACH,qBAAa,IAAK,YAAW,SAAS;IACrC,OAAO,CAAC,IAAI,CAAS;IACrB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,UAAU,CAAC,CAA2B;IAG9C,OAAO,CAAC,UAAU,CAAC,CAAS;IAC5B,OAAO,CAAC,WAAW,CAAC,CAAS;IAC7B,OAAO,CAAC,WAAW,CAAC,CAAW;gBAEnB,IAAI,GAAE,MAAW,EAAE,QAAQ,GAAE,MAAU,EAAE,QAAQ,GAAE,MAAU,EAAE,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM;IAOhH,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAO3B,aAAa,CAAC,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI;IAO1D,UAAU,IAAI,IAAI;IAMlB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE;CA6D/B"}
@@ -0,0 +1,88 @@
1
+ import { applyBackgroundToLine, visibleWidth, wrapTextWithAnsi } from "../utils.js";
2
+ /**
3
+ * Text component - displays multi-line text with word wrapping
4
+ */
5
+ export class Text {
6
+ text;
7
+ paddingX; // Left/right padding
8
+ paddingY; // Top/bottom padding
9
+ customBgFn;
10
+ // Cache for rendered output
11
+ cachedText;
12
+ cachedWidth;
13
+ cachedLines;
14
+ constructor(text = "", paddingX = 1, paddingY = 1, customBgFn) {
15
+ this.text = text;
16
+ this.paddingX = paddingX;
17
+ this.paddingY = paddingY;
18
+ this.customBgFn = customBgFn;
19
+ }
20
+ setText(text) {
21
+ this.text = text;
22
+ this.cachedText = undefined;
23
+ this.cachedWidth = undefined;
24
+ this.cachedLines = undefined;
25
+ }
26
+ setCustomBgFn(customBgFn) {
27
+ this.customBgFn = customBgFn;
28
+ this.cachedText = undefined;
29
+ this.cachedWidth = undefined;
30
+ this.cachedLines = undefined;
31
+ }
32
+ invalidate() {
33
+ this.cachedText = undefined;
34
+ this.cachedWidth = undefined;
35
+ this.cachedLines = undefined;
36
+ }
37
+ render(width) {
38
+ // Check cache
39
+ if (this.cachedLines && this.cachedText === this.text && this.cachedWidth === width) {
40
+ return this.cachedLines;
41
+ }
42
+ // Don't render anything if there's no actual text
43
+ if (!this.text || this.text.trim() === "") {
44
+ const result = [];
45
+ this.cachedText = this.text;
46
+ this.cachedWidth = width;
47
+ this.cachedLines = result;
48
+ return result;
49
+ }
50
+ // Replace tabs with 3 spaces
51
+ const normalizedText = this.text.replace(/\t/g, " ");
52
+ // Calculate content width (subtract left/right margins)
53
+ const contentWidth = Math.max(1, width - this.paddingX * 2);
54
+ // Wrap text (this preserves ANSI codes but does NOT pad)
55
+ const wrappedLines = wrapTextWithAnsi(normalizedText, contentWidth);
56
+ // Add margins and background to each line
57
+ const leftMargin = " ".repeat(this.paddingX);
58
+ const rightMargin = " ".repeat(this.paddingX);
59
+ const contentLines = [];
60
+ for (const line of wrappedLines) {
61
+ // Add margins
62
+ const lineWithMargins = leftMargin + line + rightMargin;
63
+ // Apply background if specified (this also pads to full width)
64
+ if (this.customBgFn) {
65
+ contentLines.push(applyBackgroundToLine(lineWithMargins, width, this.customBgFn));
66
+ }
67
+ else {
68
+ // No background - just pad to width with spaces
69
+ const visibleLen = visibleWidth(lineWithMargins);
70
+ const paddingNeeded = Math.max(0, width - visibleLen);
71
+ contentLines.push(lineWithMargins + " ".repeat(paddingNeeded));
72
+ }
73
+ }
74
+ // Add top/bottom padding (empty lines)
75
+ const emptyLine = " ".repeat(width);
76
+ const emptyLines = [];
77
+ for (let i = 0; i < this.paddingY; i++) {
78
+ const line = this.customBgFn ? applyBackgroundToLine(emptyLine, width, this.customBgFn) : emptyLine;
79
+ emptyLines.push(line);
80
+ }
81
+ const result = [...emptyLines, ...contentLines, ...emptyLines];
82
+ // Update cache
83
+ this.cachedText = this.text;
84
+ this.cachedWidth = width;
85
+ this.cachedLines = result;
86
+ return result.length > 0 ? result : [""];
87
+ }
88
+ }
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Toast component for displaying temporary notifications.
3
+ */
4
+ import type { Component } from "../tui.js";
5
+ /**
6
+ * Toast severity levels.
7
+ */
8
+ export type ToastType = "info" | "success" | "warning" | "error";
9
+ /**
10
+ * Theme functions for Toast styling.
11
+ */
12
+ export interface ToastTheme {
13
+ /** Style function for info toasts */
14
+ info: (text: string) => string;
15
+ /** Style function for success toasts */
16
+ success: (text: string) => string;
17
+ /** Style function for warning toasts */
18
+ warning: (text: string) => string;
19
+ /** Style function for error toasts */
20
+ error: (text: string) => string;
21
+ /** Optional border character (default: "│") */
22
+ borderChar?: string;
23
+ /** Optional icon for each type */
24
+ icons?: {
25
+ info?: string;
26
+ success?: string;
27
+ warning?: string;
28
+ error?: string;
29
+ };
30
+ }
31
+ /**
32
+ * Options for Toast configuration.
33
+ */
34
+ export interface ToastOptions {
35
+ /** Theme for styling the toast */
36
+ theme?: ToastTheme;
37
+ /** Toast type/severity (default: "info") */
38
+ type?: ToastType;
39
+ /** Whether to show an icon (default: true) */
40
+ showIcon?: boolean;
41
+ /** Whether to show a border (default: true) */
42
+ showBorder?: boolean;
43
+ /** Horizontal padding inside the toast (default: 1) */
44
+ paddingX?: number;
45
+ }
46
+ /**
47
+ * Toast component for displaying temporary notification messages.
48
+ *
49
+ * Features:
50
+ * - Multiple severity levels (info, success, warning, error)
51
+ * - Optional icons
52
+ * - Configurable border
53
+ * - Theming support
54
+ */
55
+ export declare class Toast implements Component {
56
+ private message;
57
+ private type;
58
+ private theme;
59
+ private showIcon;
60
+ private showBorder;
61
+ private paddingX;
62
+ private cachedMessage?;
63
+ private cachedType?;
64
+ private cachedWidth?;
65
+ private cachedLines?;
66
+ constructor(message: string, options?: ToastOptions);
67
+ setMessage(message: string): void;
68
+ setType(type: ToastType): void;
69
+ setTheme(theme: ToastTheme): void;
70
+ invalidate(): void;
71
+ render(width: number): string[];
72
+ }
73
+ //# sourceMappingURL=toast.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toast.d.ts","sourceRoot":"","sources":["../../src/components/toast.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAG3C;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,CAAC;AAEjE;;GAEG;AACH,MAAM,WAAW,UAAU;IAC1B,qCAAqC;IACrC,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;IAC/B,wCAAwC;IACxC,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;IAClC,wCAAwC;IACxC,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;IAClC,sCAAsC;IACtC,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;IAChC,+CAA+C;IAC/C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,kCAAkC;IAClC,KAAK,CAAC,EAAE;QACP,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,KAAK,CAAC,EAAE,MAAM,CAAC;KACf,CAAC;CACF;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC5B,kCAAkC;IAClC,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB,4CAA4C;IAC5C,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,8CAA8C;IAC9C,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,+CAA+C;IAC/C,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,uDAAuD;IACvD,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB;AAwBD;;;;;;;;GAQG;AACH,qBAAa,KAAM,YAAW,SAAS;IACtC,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,IAAI,CAAY;IACxB,OAAO,CAAC,KAAK,CAAa;IAC1B,OAAO,CAAC,QAAQ,CAAU;IAC1B,OAAO,CAAC,UAAU,CAAU;IAC5B,OAAO,CAAC,QAAQ,CAAS;IAGzB,OAAO,CAAC,aAAa,CAAC,CAAS;IAC/B,OAAO,CAAC,UAAU,CAAC,CAAY;IAC/B,OAAO,CAAC,WAAW,CAAC,CAAS;IAC7B,OAAO,CAAC,WAAW,CAAC,CAAW;gBAEnB,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,YAAiB;IASvD,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAKjC,OAAO,CAAC,IAAI,EAAE,SAAS,GAAG,IAAI;IAK9B,QAAQ,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI;IAKjC,UAAU,IAAI,IAAI;IAOlB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE;CAyD/B"}