agentlas 1.0.41 → 1.0.43
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.
- package/CHANGELOG.md +40 -8
- package/engine/agentlas-workforce.cjs +1 -1
- package/engine/commands/index.cjs +5 -5
- package/engine/hephaestus/runtime.cjs +1 -1
- package/engine/storm/storm.cjs +1 -1
- package/engine/storm/swarm.cjs +1 -1
- package/engine/ui/repl.cjs +4 -4
- package/engine/ui/{pitui-screens.cjs → screens.cjs} +143 -6
- package/engine/ui/{pitui-shell.cjs → shell.cjs} +42 -27
- package/engine/ui/width.cjs +1 -1
- package/engine/vendor/mermaid/LICENSE +205 -0
- package/engine/vendor/mermaid/ansi.js +23 -0
- package/engine/vendor/mermaid/canvas.js +366 -0
- package/engine/vendor/mermaid/graph.js +91 -0
- package/engine/vendor/mermaid/index.js +100 -0
- package/engine/vendor/mermaid/labels.js +324 -0
- package/engine/vendor/mermaid/layout-seq.js +194 -0
- package/engine/vendor/mermaid/layout.js +881 -0
- package/engine/vendor/mermaid/package.json +1 -0
- package/engine/vendor/mermaid/parse.js +1108 -0
- package/engine/vendor/mermaid/source-box.js +78 -0
- package/engine/vendor/mermaid/types.js +1 -0
- package/engine/vendor/mermaid/width-data.js +994 -0
- package/engine/vendor/mermaid/width.js +76 -0
- package/engine/vendor/tui/LICENSE +20 -0
- package/engine/vendor/tui/autocomplete.js +632 -0
- package/engine/vendor/tui/components/alt-screen-flash.js +37 -0
- package/engine/vendor/tui/components/box.js +104 -0
- package/engine/vendor/tui/components/cancellable-loader.js +35 -0
- package/engine/vendor/tui/components/editor.js +1961 -0
- package/engine/vendor/tui/components/h-stack.js +43 -0
- package/engine/vendor/tui/components/image.js +90 -0
- package/engine/vendor/tui/components/input.js +378 -0
- package/engine/vendor/tui/components/loader.js +69 -0
- package/engine/vendor/tui/components/markdown.js +806 -0
- package/engine/vendor/tui/components/scroll-view.js +173 -0
- package/engine/vendor/tui/components/select-list.js +159 -0
- package/engine/vendor/tui/components/settings-list.js +182 -0
- package/engine/vendor/tui/components/spacer.js +23 -0
- package/engine/vendor/tui/components/stack.js +111 -0
- package/engine/vendor/tui/components/text.js +89 -0
- package/engine/vendor/tui/components/truncated-text.js +51 -0
- package/engine/vendor/tui/components/v-stack.js +26 -0
- package/engine/vendor/tui/deps/east-asian-width/LICENSE +9 -0
- package/engine/vendor/tui/deps/east-asian-width/index.js +30 -0
- package/engine/vendor/tui/deps/east-asian-width/lookup-data.js +21 -0
- package/engine/vendor/tui/deps/east-asian-width/lookup.js +138 -0
- package/engine/vendor/tui/deps/east-asian-width/utilities.js +24 -0
- package/engine/vendor/tui/deps/marked/LICENSE +44 -0
- package/engine/vendor/tui/deps/marked/index.js +77 -0
- package/engine/vendor/tui/editor-component.js +2 -0
- package/engine/vendor/tui/fuzzy.js +110 -0
- package/engine/vendor/tui/index.js +42 -0
- package/engine/vendor/tui/keybindings.js +209 -0
- package/engine/vendor/tui/keys.js +1174 -0
- package/engine/vendor/tui/kill-ring.js +44 -0
- package/engine/vendor/tui/latex.js +1264 -0
- package/engine/vendor/tui/layout-node.js +6 -0
- package/engine/vendor/tui/layout.js +314 -0
- package/engine/vendor/tui/native-modifiers.js +60 -0
- package/engine/vendor/tui/package.json +1 -0
- package/engine/vendor/tui/stdin-buffer.js +361 -0
- package/engine/vendor/tui/terminal-colors.js +59 -0
- package/engine/vendor/tui/terminal-image.js +518 -0
- package/engine/vendor/tui/terminal.js +436 -0
- package/engine/vendor/tui/tui-alt-screen.js +902 -0
- package/engine/vendor/tui/tui-main-screen.js +533 -0
- package/engine/vendor/tui/tui.js +937 -0
- package/engine/vendor/tui/undo-stack.js +25 -0
- package/engine/vendor/tui/utils.js +1191 -0
- package/engine/vendor/tui/word-navigation.js +96 -0
- package/package.json +2 -6
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { LAYOUT_NODE } from "../layout-node.js";
|
|
2
|
+
import { Container } from "../tui.js";
|
|
3
|
+
export class ScrollView extends Container {
|
|
4
|
+
child;
|
|
5
|
+
followEnd;
|
|
6
|
+
primary;
|
|
7
|
+
overscroll;
|
|
8
|
+
scrollbarStyle;
|
|
9
|
+
currentScrollbar;
|
|
10
|
+
scrollbarHideDelayMs;
|
|
11
|
+
currentScrollTop = 0;
|
|
12
|
+
contentHeight = 0;
|
|
13
|
+
currentViewportHeight = 0;
|
|
14
|
+
followingEnd;
|
|
15
|
+
requestRenderCallback;
|
|
16
|
+
transientScrollbarVisible = false;
|
|
17
|
+
scrollbarActive = false;
|
|
18
|
+
scrollbarHideTimer;
|
|
19
|
+
constructor(component, options = {}) {
|
|
20
|
+
super();
|
|
21
|
+
if (options.axis !== undefined && options.axis !== "vertical") {
|
|
22
|
+
throw new Error(`Unsupported ScrollView axis: ${options.axis}`);
|
|
23
|
+
}
|
|
24
|
+
this.child = component;
|
|
25
|
+
this.children.push(component);
|
|
26
|
+
this.followEnd = (options.follow ?? "none") === "end";
|
|
27
|
+
this.followingEnd = this.followEnd;
|
|
28
|
+
this.primary = options.primary ?? false;
|
|
29
|
+
this.overscroll = options.overscroll ?? "chain";
|
|
30
|
+
this.currentScrollbar = options.scrollbar ?? "hidden";
|
|
31
|
+
this.scrollbarStyle = options.scrollbarStyle ?? ((text) => `\x1b[100m${text}\x1b[49m`);
|
|
32
|
+
this.scrollbarHideDelayMs = Math.max(0, Math.floor(options.scrollbarHideDelayMs ?? 1000));
|
|
33
|
+
}
|
|
34
|
+
get scrollTop() {
|
|
35
|
+
return this.currentScrollTop;
|
|
36
|
+
}
|
|
37
|
+
get isFollowingEnd() {
|
|
38
|
+
return this.followingEnd;
|
|
39
|
+
}
|
|
40
|
+
get viewportHeight() {
|
|
41
|
+
return this.currentViewportHeight;
|
|
42
|
+
}
|
|
43
|
+
get scrollbar() {
|
|
44
|
+
return this.currentScrollbar;
|
|
45
|
+
}
|
|
46
|
+
get isScrollbarVisible() {
|
|
47
|
+
if (this.scrollbar === "always")
|
|
48
|
+
return this.currentViewportHeight > 0;
|
|
49
|
+
return (this.scrollbar === "auto" && this.contentHeight > this.currentViewportHeight && this.transientScrollbarVisible);
|
|
50
|
+
}
|
|
51
|
+
setScrollbar(scrollbar) {
|
|
52
|
+
if (scrollbar === this.currentScrollbar)
|
|
53
|
+
return;
|
|
54
|
+
this.currentScrollbar = scrollbar;
|
|
55
|
+
if (scrollbar !== "auto")
|
|
56
|
+
this.hideTransientScrollbar();
|
|
57
|
+
else if (this.scrollbarActive)
|
|
58
|
+
this.markScrollbarActivity();
|
|
59
|
+
this.requestRenderCallback?.();
|
|
60
|
+
}
|
|
61
|
+
getContentWidth(width) {
|
|
62
|
+
return this.scrollbar === "always" && width > 1 ? width - 1 : width;
|
|
63
|
+
}
|
|
64
|
+
markScrollbarActivity() {
|
|
65
|
+
if (this.scrollbar !== "auto" || this.contentHeight <= this.currentViewportHeight)
|
|
66
|
+
return;
|
|
67
|
+
this.transientScrollbarVisible = true;
|
|
68
|
+
if (this.scrollbarHideTimer) {
|
|
69
|
+
clearTimeout(this.scrollbarHideTimer);
|
|
70
|
+
this.scrollbarHideTimer = undefined;
|
|
71
|
+
}
|
|
72
|
+
if (this.scrollbarActive)
|
|
73
|
+
return;
|
|
74
|
+
this.scrollbarHideTimer = setTimeout(() => {
|
|
75
|
+
this.scrollbarHideTimer = undefined;
|
|
76
|
+
this.transientScrollbarVisible = false;
|
|
77
|
+
this.requestRenderCallback?.();
|
|
78
|
+
}, this.scrollbarHideDelayMs);
|
|
79
|
+
this.scrollbarHideTimer.unref();
|
|
80
|
+
}
|
|
81
|
+
hideTransientScrollbar() {
|
|
82
|
+
this.transientScrollbarVisible = false;
|
|
83
|
+
if (!this.scrollbarHideTimer)
|
|
84
|
+
return;
|
|
85
|
+
clearTimeout(this.scrollbarHideTimer);
|
|
86
|
+
this.scrollbarHideTimer = undefined;
|
|
87
|
+
}
|
|
88
|
+
setScrollbarActive(active) {
|
|
89
|
+
if (active === this.scrollbarActive)
|
|
90
|
+
return;
|
|
91
|
+
this.scrollbarActive = active;
|
|
92
|
+
this.markScrollbarActivity();
|
|
93
|
+
}
|
|
94
|
+
scrollTo(scrollTop) {
|
|
95
|
+
const requested = Number.isFinite(scrollTop) ? Math.trunc(scrollTop) : this.currentScrollTop;
|
|
96
|
+
const maxScrollTop = Math.max(0, this.contentHeight - this.currentViewportHeight);
|
|
97
|
+
const next = Math.max(0, Math.min(maxScrollTop, requested));
|
|
98
|
+
if (next === this.currentScrollTop)
|
|
99
|
+
return;
|
|
100
|
+
this.currentScrollTop = next;
|
|
101
|
+
this.followingEnd = this.followEnd && next === maxScrollTop;
|
|
102
|
+
this.markScrollbarActivity();
|
|
103
|
+
this.requestRenderCallback?.();
|
|
104
|
+
}
|
|
105
|
+
scrollBy(lines) {
|
|
106
|
+
const requested = Number.isFinite(lines) ? Math.trunc(lines) : 0;
|
|
107
|
+
if (requested === 0)
|
|
108
|
+
return 0;
|
|
109
|
+
const maxScrollTop = Math.max(0, this.contentHeight - this.currentViewportHeight);
|
|
110
|
+
const start = this.followingEnd ? maxScrollTop : this.currentScrollTop;
|
|
111
|
+
const next = Math.max(0, Math.min(maxScrollTop, start + requested));
|
|
112
|
+
const moved = next - start;
|
|
113
|
+
this.currentScrollTop = next;
|
|
114
|
+
this.followingEnd = this.followEnd && next === maxScrollTop;
|
|
115
|
+
if (moved !== 0) {
|
|
116
|
+
this.markScrollbarActivity();
|
|
117
|
+
this.requestRenderCallback?.();
|
|
118
|
+
}
|
|
119
|
+
return requested - moved;
|
|
120
|
+
}
|
|
121
|
+
scrollToStart() {
|
|
122
|
+
const changed = this.currentScrollTop !== 0 ||
|
|
123
|
+
this.followingEnd !== (this.followEnd && this.contentHeight <= this.currentViewportHeight);
|
|
124
|
+
this.currentScrollTop = 0;
|
|
125
|
+
this.followingEnd = this.followEnd && this.contentHeight <= this.currentViewportHeight;
|
|
126
|
+
if (changed) {
|
|
127
|
+
this.markScrollbarActivity();
|
|
128
|
+
this.requestRenderCallback?.();
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
scrollToEnd() {
|
|
132
|
+
const next = Math.max(0, this.contentHeight - this.currentViewportHeight);
|
|
133
|
+
const changed = this.currentScrollTop !== next || this.followingEnd !== this.followEnd;
|
|
134
|
+
this.currentScrollTop = next;
|
|
135
|
+
this.followingEnd = this.followEnd;
|
|
136
|
+
if (changed) {
|
|
137
|
+
this.markScrollbarActivity();
|
|
138
|
+
this.requestRenderCallback?.();
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
updateLayout(contentHeight, viewportHeight, requestRender) {
|
|
142
|
+
this.contentHeight = Math.max(0, Math.floor(contentHeight));
|
|
143
|
+
this.currentViewportHeight = Math.max(0, Math.floor(viewportHeight));
|
|
144
|
+
this.requestRenderCallback = requestRender;
|
|
145
|
+
const maxScrollTop = Math.max(0, this.contentHeight - this.currentViewportHeight);
|
|
146
|
+
if (this.followingEnd)
|
|
147
|
+
this.currentScrollTop = maxScrollTop;
|
|
148
|
+
else
|
|
149
|
+
this.currentScrollTop = Math.max(0, Math.min(this.currentScrollTop, maxScrollTop));
|
|
150
|
+
if (this.followEnd && this.currentScrollTop === maxScrollTop)
|
|
151
|
+
this.followingEnd = true;
|
|
152
|
+
if (this.contentHeight <= this.currentViewportHeight)
|
|
153
|
+
this.hideTransientScrollbar();
|
|
154
|
+
}
|
|
155
|
+
addChild(_component) {
|
|
156
|
+
throw new Error("ScrollView has exactly one child");
|
|
157
|
+
}
|
|
158
|
+
removeChild(_component) {
|
|
159
|
+
throw new Error("ScrollView child cannot be removed");
|
|
160
|
+
}
|
|
161
|
+
clear() {
|
|
162
|
+
throw new Error("ScrollView child cannot be cleared");
|
|
163
|
+
}
|
|
164
|
+
render(width) {
|
|
165
|
+
const contentWidth = this.getContentWidth(width);
|
|
166
|
+
const lines = this.child.render(contentWidth);
|
|
167
|
+
return contentWidth === width ? lines : lines.map((line) => `${line} `);
|
|
168
|
+
}
|
|
169
|
+
[LAYOUT_NODE]() {
|
|
170
|
+
return { type: "scroll", component: this.child, state: this };
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
//# sourceMappingURL=scroll-view.js.map
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { getKeybindings } from "../keybindings.js";
|
|
2
|
+
import { truncateToWidth, visibleWidth } from "../utils.js";
|
|
3
|
+
const DEFAULT_PRIMARY_COLUMN_WIDTH = 32;
|
|
4
|
+
const PRIMARY_COLUMN_GAP = 2;
|
|
5
|
+
const MIN_DESCRIPTION_WIDTH = 10;
|
|
6
|
+
const normalizeToSingleLine = (text) => text.replace(/[\r\n]+/g, " ").trim();
|
|
7
|
+
const clamp = (value, min, max) => Math.max(min, Math.min(value, max));
|
|
8
|
+
export class SelectList {
|
|
9
|
+
items = [];
|
|
10
|
+
filteredItems = [];
|
|
11
|
+
selectedIndex = 0;
|
|
12
|
+
maxVisible = 5;
|
|
13
|
+
theme;
|
|
14
|
+
layout;
|
|
15
|
+
onSelect;
|
|
16
|
+
onCancel;
|
|
17
|
+
onSelectionChange;
|
|
18
|
+
constructor(items, maxVisible, theme, layout = {}) {
|
|
19
|
+
this.items = items;
|
|
20
|
+
this.filteredItems = items;
|
|
21
|
+
this.maxVisible = maxVisible;
|
|
22
|
+
this.theme = theme;
|
|
23
|
+
this.layout = layout;
|
|
24
|
+
}
|
|
25
|
+
setFilter(filter) {
|
|
26
|
+
this.filteredItems = this.items.filter((item) => item.value.toLowerCase().startsWith(filter.toLowerCase()));
|
|
27
|
+
// Reset selection when filter changes
|
|
28
|
+
this.selectedIndex = 0;
|
|
29
|
+
}
|
|
30
|
+
setSelectedIndex(index) {
|
|
31
|
+
this.selectedIndex = Math.max(0, Math.min(index, this.filteredItems.length - 1));
|
|
32
|
+
}
|
|
33
|
+
invalidate() {
|
|
34
|
+
// No cached state to invalidate currently
|
|
35
|
+
}
|
|
36
|
+
render(width) {
|
|
37
|
+
const lines = [];
|
|
38
|
+
// If no items match filter, show message
|
|
39
|
+
if (this.filteredItems.length === 0) {
|
|
40
|
+
lines.push(this.theme.noMatch(" No matching commands"));
|
|
41
|
+
return lines;
|
|
42
|
+
}
|
|
43
|
+
const primaryColumnWidth = this.getPrimaryColumnWidth();
|
|
44
|
+
// Calculate visible range with scrolling
|
|
45
|
+
const startIndex = Math.max(0, Math.min(this.selectedIndex - Math.floor(this.maxVisible / 2), this.filteredItems.length - this.maxVisible));
|
|
46
|
+
const endIndex = Math.min(startIndex + this.maxVisible, this.filteredItems.length);
|
|
47
|
+
// Render visible items
|
|
48
|
+
for (let i = startIndex; i < endIndex; i++) {
|
|
49
|
+
const item = this.filteredItems[i];
|
|
50
|
+
if (!item)
|
|
51
|
+
continue;
|
|
52
|
+
const isSelected = i === this.selectedIndex;
|
|
53
|
+
const descriptionSingleLine = item.description ? normalizeToSingleLine(item.description) : undefined;
|
|
54
|
+
lines.push(this.renderItem(item, isSelected, width, descriptionSingleLine, primaryColumnWidth));
|
|
55
|
+
}
|
|
56
|
+
// Add scroll indicators if needed
|
|
57
|
+
if (startIndex > 0 || endIndex < this.filteredItems.length) {
|
|
58
|
+
const scrollText = ` (${this.selectedIndex + 1}/${this.filteredItems.length})`;
|
|
59
|
+
// Truncate if too long for terminal
|
|
60
|
+
lines.push(this.theme.scrollInfo(truncateToWidth(scrollText, width - 2, "")));
|
|
61
|
+
}
|
|
62
|
+
return lines;
|
|
63
|
+
}
|
|
64
|
+
handleInput(keyData) {
|
|
65
|
+
const kb = getKeybindings();
|
|
66
|
+
// Up arrow - wrap to bottom when at top
|
|
67
|
+
if (kb.matches(keyData, "tui.select.up")) {
|
|
68
|
+
this.selectedIndex = this.selectedIndex === 0 ? this.filteredItems.length - 1 : this.selectedIndex - 1;
|
|
69
|
+
this.notifySelectionChange();
|
|
70
|
+
}
|
|
71
|
+
// Down arrow - wrap to top when at bottom
|
|
72
|
+
else if (kb.matches(keyData, "tui.select.down")) {
|
|
73
|
+
this.selectedIndex = this.selectedIndex === this.filteredItems.length - 1 ? 0 : this.selectedIndex + 1;
|
|
74
|
+
this.notifySelectionChange();
|
|
75
|
+
}
|
|
76
|
+
// Enter
|
|
77
|
+
else if (kb.matches(keyData, "tui.select.confirm")) {
|
|
78
|
+
const selectedItem = this.filteredItems[this.selectedIndex];
|
|
79
|
+
if (selectedItem && this.onSelect) {
|
|
80
|
+
this.onSelect(selectedItem);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
// Escape or Ctrl+C
|
|
84
|
+
else if (kb.matches(keyData, "tui.select.cancel")) {
|
|
85
|
+
if (this.onCancel) {
|
|
86
|
+
this.onCancel();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
renderItem(item, isSelected, width, descriptionSingleLine, primaryColumnWidth) {
|
|
91
|
+
const prefix = isSelected ? "→ " : " ";
|
|
92
|
+
const prefixWidth = visibleWidth(prefix);
|
|
93
|
+
if (descriptionSingleLine && width > 40) {
|
|
94
|
+
const effectivePrimaryColumnWidth = Math.max(1, Math.min(primaryColumnWidth, width - prefixWidth - 4));
|
|
95
|
+
const maxPrimaryWidth = Math.max(1, effectivePrimaryColumnWidth - PRIMARY_COLUMN_GAP);
|
|
96
|
+
const truncatedValue = this.truncatePrimary(item, isSelected, maxPrimaryWidth, effectivePrimaryColumnWidth);
|
|
97
|
+
const truncatedValueWidth = visibleWidth(truncatedValue);
|
|
98
|
+
const spacing = " ".repeat(Math.max(1, effectivePrimaryColumnWidth - truncatedValueWidth));
|
|
99
|
+
const descriptionStart = prefixWidth + truncatedValueWidth + spacing.length;
|
|
100
|
+
const remainingWidth = width - descriptionStart - 2; // -2 for safety
|
|
101
|
+
if (remainingWidth > MIN_DESCRIPTION_WIDTH) {
|
|
102
|
+
const truncatedDesc = truncateToWidth(descriptionSingleLine, remainingWidth, "");
|
|
103
|
+
if (isSelected) {
|
|
104
|
+
return this.theme.selectedText(`${prefix}${truncatedValue}${spacing}${truncatedDesc}`);
|
|
105
|
+
}
|
|
106
|
+
const descText = this.theme.description(spacing + truncatedDesc);
|
|
107
|
+
return prefix + truncatedValue + descText;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
const maxWidth = width - prefixWidth - 2;
|
|
111
|
+
const truncatedValue = this.truncatePrimary(item, isSelected, maxWidth, maxWidth);
|
|
112
|
+
if (isSelected) {
|
|
113
|
+
return this.theme.selectedText(`${prefix}${truncatedValue}`);
|
|
114
|
+
}
|
|
115
|
+
return prefix + truncatedValue;
|
|
116
|
+
}
|
|
117
|
+
getPrimaryColumnWidth() {
|
|
118
|
+
const { min, max } = this.getPrimaryColumnBounds();
|
|
119
|
+
const widestPrimary = this.filteredItems.reduce((widest, item) => {
|
|
120
|
+
return Math.max(widest, visibleWidth(this.getDisplayValue(item)) + PRIMARY_COLUMN_GAP);
|
|
121
|
+
}, 0);
|
|
122
|
+
return clamp(widestPrimary, min, max);
|
|
123
|
+
}
|
|
124
|
+
getPrimaryColumnBounds() {
|
|
125
|
+
const rawMin = this.layout.minPrimaryColumnWidth ?? this.layout.maxPrimaryColumnWidth ?? DEFAULT_PRIMARY_COLUMN_WIDTH;
|
|
126
|
+
const rawMax = this.layout.maxPrimaryColumnWidth ?? this.layout.minPrimaryColumnWidth ?? DEFAULT_PRIMARY_COLUMN_WIDTH;
|
|
127
|
+
return {
|
|
128
|
+
min: Math.max(1, Math.min(rawMin, rawMax)),
|
|
129
|
+
max: Math.max(1, Math.max(rawMin, rawMax)),
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
truncatePrimary(item, isSelected, maxWidth, columnWidth) {
|
|
133
|
+
const displayValue = this.getDisplayValue(item);
|
|
134
|
+
const truncatedValue = this.layout.truncatePrimary
|
|
135
|
+
? this.layout.truncatePrimary({
|
|
136
|
+
text: displayValue,
|
|
137
|
+
maxWidth,
|
|
138
|
+
columnWidth,
|
|
139
|
+
item,
|
|
140
|
+
isSelected,
|
|
141
|
+
})
|
|
142
|
+
: truncateToWidth(displayValue, maxWidth, "");
|
|
143
|
+
return truncateToWidth(truncatedValue, maxWidth, "");
|
|
144
|
+
}
|
|
145
|
+
getDisplayValue(item) {
|
|
146
|
+
return item.label || item.value;
|
|
147
|
+
}
|
|
148
|
+
notifySelectionChange() {
|
|
149
|
+
const selectedItem = this.filteredItems[this.selectedIndex];
|
|
150
|
+
if (selectedItem && this.onSelectionChange) {
|
|
151
|
+
this.onSelectionChange(selectedItem);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
getSelectedItem() {
|
|
155
|
+
const item = this.filteredItems[this.selectedIndex];
|
|
156
|
+
return item || null;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
//# sourceMappingURL=select-list.js.map
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { fuzzyFilter } from "../fuzzy.js";
|
|
2
|
+
import { getKeybindings } 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 = getKeybindings();
|
|
116
|
+
const displayItems = this.searchEnabled ? this.filteredItems : this.items;
|
|
117
|
+
if (kb.matches(data, "tui.select.up")) {
|
|
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, "tui.select.down")) {
|
|
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, "tui.select.confirm") ||
|
|
128
|
+
(data === " " && (!this.searchEnabled || this.searchInput?.getValue().length === 0))) {
|
|
129
|
+
this.activateItem();
|
|
130
|
+
}
|
|
131
|
+
else if (kb.matches(data, "tui.select.cancel")) {
|
|
132
|
+
this.onCancel();
|
|
133
|
+
}
|
|
134
|
+
else if (this.searchEnabled && this.searchInput) {
|
|
135
|
+
this.searchInput.handleInput(data);
|
|
136
|
+
this.applyFilter(this.searchInput.getValue());
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
activateItem() {
|
|
140
|
+
const item = this.searchEnabled ? this.filteredItems[this.selectedIndex] : this.items[this.selectedIndex];
|
|
141
|
+
if (!item)
|
|
142
|
+
return;
|
|
143
|
+
if (item.submenu) {
|
|
144
|
+
// Open submenu, passing current value so it can pre-select correctly
|
|
145
|
+
this.submenuItemIndex = this.selectedIndex;
|
|
146
|
+
this.submenuComponent = item.submenu(item.currentValue, (selectedValue) => {
|
|
147
|
+
if (selectedValue !== undefined) {
|
|
148
|
+
item.currentValue = selectedValue;
|
|
149
|
+
this.onChange(item.id, selectedValue);
|
|
150
|
+
}
|
|
151
|
+
this.closeSubmenu();
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
else if (item.values && item.values.length > 0) {
|
|
155
|
+
// Cycle through values
|
|
156
|
+
const currentIndex = item.values.indexOf(item.currentValue);
|
|
157
|
+
const nextIndex = (currentIndex + 1) % item.values.length;
|
|
158
|
+
const newValue = item.values[nextIndex];
|
|
159
|
+
item.currentValue = newValue;
|
|
160
|
+
this.onChange(item.id, newValue);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
closeSubmenu() {
|
|
164
|
+
this.submenuComponent = null;
|
|
165
|
+
// Restore selection to the item that opened the submenu
|
|
166
|
+
if (this.submenuItemIndex !== null) {
|
|
167
|
+
this.selectedIndex = this.submenuItemIndex;
|
|
168
|
+
this.submenuItemIndex = null;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
applyFilter(query) {
|
|
172
|
+
this.filteredItems = fuzzyFilter(this.items, query, (item) => item.label);
|
|
173
|
+
this.selectedIndex = 0;
|
|
174
|
+
}
|
|
175
|
+
addHintLine(lines, width) {
|
|
176
|
+
lines.push("");
|
|
177
|
+
lines.push(truncateToWidth(this.theme.hint(this.searchEnabled
|
|
178
|
+
? " Type to search · Enter/Space to change · Esc to cancel"
|
|
179
|
+
: " Enter/Space to change · Esc to cancel"), width));
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
//# sourceMappingURL=settings-list.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
}
|
|
23
|
+
//# sourceMappingURL=spacer.js.map
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { LAYOUT_NODE } from "../layout-node.js";
|
|
2
|
+
import { Container } from "../tui.js";
|
|
3
|
+
function isStackEntry(child) {
|
|
4
|
+
return !("render" in child);
|
|
5
|
+
}
|
|
6
|
+
function normalizeSize(value, fallback) {
|
|
7
|
+
return value === undefined || !Number.isFinite(value) ? fallback : Math.max(0, Math.floor(value));
|
|
8
|
+
}
|
|
9
|
+
export class Stack extends Container {
|
|
10
|
+
entries = [];
|
|
11
|
+
gap;
|
|
12
|
+
align;
|
|
13
|
+
constructor(children = [], options = {}) {
|
|
14
|
+
super();
|
|
15
|
+
this.gap = normalizeSize(options.gap, 0);
|
|
16
|
+
this.align = options.align ?? "stretch";
|
|
17
|
+
for (const child of children) {
|
|
18
|
+
if (isStackEntry(child))
|
|
19
|
+
this.addChild(child.component, child);
|
|
20
|
+
else
|
|
21
|
+
this.addChild(child);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
addChild(component, options = {}) {
|
|
25
|
+
super.addChild(component);
|
|
26
|
+
this.entries.push({
|
|
27
|
+
component,
|
|
28
|
+
...(options.basis === undefined ? {} : { basis: options.basis }),
|
|
29
|
+
...(options.grow === undefined ? {} : { grow: normalizeSize(options.grow, 0) }),
|
|
30
|
+
...(options.shrink === undefined ? {} : { shrink: normalizeSize(options.shrink, 1) }),
|
|
31
|
+
...(options.minSize === undefined ? {} : { minSize: normalizeSize(options.minSize, 0) }),
|
|
32
|
+
...(options.maxSize === undefined ? {} : { maxSize: normalizeSize(options.maxSize, Number.MAX_SAFE_INTEGER) }),
|
|
33
|
+
...(options.visible === undefined ? {} : { visible: options.visible }),
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
removeChild(component) {
|
|
37
|
+
super.removeChild(component);
|
|
38
|
+
const index = this.entries.findIndex((entry) => entry.component === component);
|
|
39
|
+
if (index !== -1)
|
|
40
|
+
this.entries.splice(index, 1);
|
|
41
|
+
}
|
|
42
|
+
clear() {
|
|
43
|
+
super.clear();
|
|
44
|
+
this.entries.length = 0;
|
|
45
|
+
}
|
|
46
|
+
[LAYOUT_NODE]() {
|
|
47
|
+
return {
|
|
48
|
+
type: this.layoutType,
|
|
49
|
+
entries: this.entries,
|
|
50
|
+
gap: this.gap,
|
|
51
|
+
align: this.align,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
export function visibleStackEntries(entries, viewport) {
|
|
56
|
+
return entries.filter((entry) => entry.visible?.(viewport) ?? true);
|
|
57
|
+
}
|
|
58
|
+
function clampSize(size, entry) {
|
|
59
|
+
const min = Math.max(0, Math.floor(entry.minSize ?? 0));
|
|
60
|
+
const max = Math.max(min, Math.floor(entry.maxSize ?? Number.MAX_SAFE_INTEGER));
|
|
61
|
+
return Math.max(min, Math.min(max, Math.max(0, Math.floor(size))));
|
|
62
|
+
}
|
|
63
|
+
function distribute(sizes, entries, amount, mode) {
|
|
64
|
+
let remaining = amount;
|
|
65
|
+
while (remaining > 0) {
|
|
66
|
+
const candidates = entries
|
|
67
|
+
.map((entry, index) => ({ entry, index }))
|
|
68
|
+
.filter(({ entry, index }) => {
|
|
69
|
+
if (mode === "grow") {
|
|
70
|
+
return (entry.grow ?? 0) > 0 && sizes[index] < (entry.maxSize ?? Number.MAX_SAFE_INTEGER);
|
|
71
|
+
}
|
|
72
|
+
return (entry.shrink ?? 1) > 0 && sizes[index] > (entry.minSize ?? 0);
|
|
73
|
+
});
|
|
74
|
+
if (candidates.length === 0)
|
|
75
|
+
return;
|
|
76
|
+
const totalWeight = candidates.reduce((sum, { entry, index }) => {
|
|
77
|
+
return sum + (mode === "grow" ? (entry.grow ?? 0) : (entry.shrink ?? 1) * Math.max(1, sizes[index]));
|
|
78
|
+
}, 0);
|
|
79
|
+
let distributed = 0;
|
|
80
|
+
for (const { entry, index } of candidates) {
|
|
81
|
+
if (remaining <= 0)
|
|
82
|
+
break;
|
|
83
|
+
const weight = mode === "grow" ? (entry.grow ?? 0) : (entry.shrink ?? 1) * Math.max(1, sizes[index]);
|
|
84
|
+
const proposed = Math.max(1, Math.floor((remaining * weight) / totalWeight));
|
|
85
|
+
const capacity = mode === "grow"
|
|
86
|
+
? (entry.maxSize ?? Number.MAX_SAFE_INTEGER) - sizes[index]
|
|
87
|
+
: sizes[index] - (entry.minSize ?? 0);
|
|
88
|
+
const delta = Math.min(remaining, proposed, capacity);
|
|
89
|
+
if (delta <= 0)
|
|
90
|
+
continue;
|
|
91
|
+
sizes[index] = sizes[index] + (mode === "grow" ? delta : -delta);
|
|
92
|
+
remaining -= delta;
|
|
93
|
+
distributed += delta;
|
|
94
|
+
}
|
|
95
|
+
if (distributed === 0)
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
export function allocateStackSizes(entries, intrinsicSizes, availableSize, gap) {
|
|
100
|
+
const sizes = entries.map((entry, index) => clampSize(entry.basis === undefined || entry.basis === "auto" ? (intrinsicSizes[index] ?? 0) : entry.basis, entry));
|
|
101
|
+
if (availableSize === undefined)
|
|
102
|
+
return sizes;
|
|
103
|
+
const contentSize = Math.max(0, Math.floor(availableSize) - Math.max(0, entries.length - 1) * gap);
|
|
104
|
+
const total = sizes.reduce((sum, size) => sum + size, 0);
|
|
105
|
+
if (total < contentSize)
|
|
106
|
+
distribute(sizes, entries, contentSize - total, "grow");
|
|
107
|
+
else if (total > contentSize)
|
|
108
|
+
distribute(sizes, entries, total - contentSize, "shrink");
|
|
109
|
+
return sizes;
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=stack.js.map
|