@visual-z/xeno 0.2.1 → 0.4.0
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 +18 -0
- package/README.md +126 -34
- package/docs/app-server.md +84 -0
- package/docs/install.md +51 -13
- package/docs/providers.md +24 -3
- package/package.json +7 -5
- package/src/apps/app-server.ts +28 -0
- package/src/apps/approve.ts +3 -3
- package/src/apps/cli.ts +25 -10
- package/src/apps/commands.ts +45 -8
- package/src/apps/completions.ts +78 -22
- package/src/apps/control-transport.ts +89 -0
- package/src/apps/image-draft.ts +46 -0
- package/src/apps/model-catalog.ts +2 -1
- package/src/apps/project-trust.ts +2 -42
- package/src/apps/provider-connect.ts +346 -0
- package/src/apps/render.ts +22 -47
- package/src/apps/resources.ts +5 -2
- package/src/apps/shell.ts +333 -1542
- package/src/apps/startup-input.ts +45 -9
- package/src/apps/startup.ts +149 -94
- package/src/apps/ui/app.ts +1553 -0
- package/src/apps/ui/control-model.ts +26 -0
- package/src/apps/ui/extension-host.ts +194 -0
- package/src/apps/ui/image-cache.ts +78 -0
- package/src/apps/ui/palette.ts +88 -0
- package/src/apps/ui/project.ts +127 -0
- package/src/apps/ui/standalone.ts +146 -0
- package/src/apps/ui/status-model.ts +68 -0
- package/src/apps/ui/surface.ts +86 -0
- package/src/apps/ui/theme.ts +86 -0
- package/src/core/acceptance.ts +107 -0
- package/src/core/action-defaults.ts +47 -295
- package/src/core/benchmark.ts +2 -2
- package/src/core/branch-receipt.ts +24 -0
- package/src/core/checkpoints.ts +64 -0
- package/src/core/churn.ts +2 -0
- package/src/core/command-artifacts.ts +94 -0
- package/src/core/command-contract.ts +35 -0
- package/src/core/completion-action.ts +20 -0
- package/src/core/completion-review.ts +37 -21
- package/src/core/context-detail.ts +37 -0
- package/src/core/context-policy.ts +74 -1
- package/src/core/continuation.ts +17 -2
- package/src/core/control-protocol.ts +62 -0
- package/src/core/control-view.ts +42 -0
- package/src/core/derive.ts +29 -3
- package/src/core/draft-images.ts +56 -0
- package/src/core/environment.ts +145 -0
- package/src/core/evaluation-coverage.ts +74 -0
- package/src/core/event-validation.ts +81 -6
- package/src/core/events.ts +99 -3
- package/src/core/evidence-links.ts +7 -0
- package/src/core/evidence.ts +13 -3
- package/src/core/execution.ts +8 -2
- package/src/core/experiment.ts +133 -0
- package/src/core/export.ts +9 -0
- package/src/core/failure-recovery.ts +173 -0
- package/src/core/file-precondition.ts +72 -0
- package/src/core/handoff.ts +65 -4
- package/src/core/harness-diagnostics.ts +206 -0
- package/src/core/history-query.ts +38 -2
- package/src/core/history.ts +38 -1
- package/src/core/integration-health.ts +34 -0
- package/src/core/keymap.ts +8 -20
- package/src/core/model-picker.ts +64 -0
- package/src/core/native-eval.ts +25 -0
- package/src/core/note-guidance.ts +34 -0
- package/src/core/oauth-fields.ts +44 -0
- package/src/core/observation-view.ts +49 -8
- package/src/core/permissions.ts +24 -2
- package/src/core/process-receipt.ts +105 -0
- package/src/core/process-state.ts +37 -0
- package/src/core/program-status.ts +31 -0
- package/src/core/project.ts +70 -19
- package/src/core/prompt-policy.ts +37 -0
- package/src/core/query-eval-contract.ts +14 -0
- package/src/core/read-observation.ts +82 -0
- package/src/core/recovery-corpus.ts +17 -0
- package/src/core/recovery-evaluation.ts +60 -0
- package/src/core/recovery-sources.ts +74 -0
- package/src/core/request-progress.ts +87 -0
- package/src/core/request-state.ts +114 -0
- package/src/core/runtime-target.ts +94 -0
- package/src/core/search-observation.ts +97 -0
- package/src/core/session-tree.ts +147 -0
- package/src/core/settings.ts +33 -10
- package/src/core/skills.ts +44 -0
- package/src/core/sql-query.ts +211 -0
- package/src/core/theme.ts +36 -58
- package/src/core/tool-contract.ts +51 -2
- package/src/core/tool-discovery.ts +87 -0
- package/src/core/tool-failure.ts +60 -0
- package/src/core/tool-input.ts +6 -0
- package/src/core/tool-mode-protocol.ts +25 -0
- package/src/core/transcript.ts +19 -4
- package/src/core/trial-lifecycle.ts +14 -0
- package/src/core/tui-mode.ts +29 -0
- package/src/core/update-check.ts +97 -0
- package/src/core/version.ts +55 -0
- package/src/core/work-state.ts +49 -3
- package/src/core/working-set.ts +91 -0
- package/src/runtime/auth.ts +11 -4
- package/src/runtime/branch-jobs.ts +36 -0
- package/src/runtime/catalog.ts +13 -3
- package/src/runtime/clipboard.ts +15 -4
- package/src/runtime/command-artifacts.ts +64 -0
- package/src/runtime/control-connection.ts +104 -0
- package/src/runtime/environment-tools.ts +60 -0
- package/src/runtime/evidence-notes.ts +4 -2
- package/src/runtime/exec-sessions.ts +206 -61
- package/src/runtime/execution-control.ts +1 -0
- package/src/runtime/extension-ui.ts +22 -30
- package/src/runtime/extensions.ts +95 -16
- package/src/runtime/harness-comparison.ts +27 -7
- package/src/runtime/harness-eval.ts +462 -0
- package/src/runtime/history-cache.ts +57 -0
- package/src/runtime/history-tools.ts +62 -12
- package/src/runtime/integrations.ts +210 -0
- package/src/runtime/loop.ts +1088 -282
- package/src/runtime/model-discovery.ts +208 -0
- package/src/runtime/model.ts +9 -0
- package/src/runtime/native-eval-fixtures.ts +33 -0
- package/src/runtime/native-eval.ts +146 -0
- package/src/runtime/oauth.ts +80 -3
- package/src/runtime/pi-provider.ts +169 -12
- package/src/runtime/program-status.ts +38 -0
- package/src/runtime/provider-connect.ts +109 -0
- package/src/runtime/provider-presets.ts +87 -0
- package/src/runtime/provider-request.ts +13 -2
- package/src/runtime/provider.ts +23 -9
- package/src/runtime/query-eval-verifier.ts +28 -0
- package/src/runtime/recovery-coverage.ts +71 -0
- package/src/runtime/recovery-evidence.ts +76 -0
- package/src/runtime/recovery-fixtures.ts +116 -0
- package/src/runtime/runtime-target.ts +149 -0
- package/src/runtime/session-control.ts +198 -0
- package/src/runtime/tool-broker.ts +137 -0
- package/src/runtime/tool-discovery.ts +57 -0
- package/src/runtime/tool-mode-eval.ts +146 -0
- package/src/runtime/tool-queue.ts +77 -0
- package/src/runtime/tools.ts +628 -183
- package/src/runtime/trial-control.ts +45 -0
- package/src/runtime/update-check.ts +47 -0
- package/src/runtime/window-trial.ts +2 -1
- package/src/runtime/working-notes.ts +33 -3
- package/src/runtime/workspace-lifecycle.ts +97 -0
- package/src/store/acceptance.ts +15 -0
- package/src/store/checkpoint-history.ts +43 -0
- package/src/store/command-artifacts.ts +96 -0
- package/src/store/command.ts +65 -37
- package/src/store/file-checkpoints.ts +104 -0
- package/src/store/file-index.ts +13 -1
- package/src/store/git-checkpoints.ts +67 -0
- package/src/store/observations.ts +61 -20
- package/src/store/process-receipts.ts +34 -0
- package/src/store/query-source.ts +13 -8
- package/src/store/recovery.ts +2 -3
- package/src/store/replay.ts +16 -4
- package/src/store/runtime-target.ts +64 -0
- package/src/store/search.ts +171 -132
- package/src/store/session-archive.ts +4 -0
- package/src/store/source-cancellation.ts +6 -0
- package/src/store/update-cache.ts +36 -0
- package/src/store/workspace-observation.ts +113 -0
- package/src/tui/ansi-spans.ts +126 -0
- package/src/tui/style.ts +19 -16
- package/src/tui/ui/atomic-draft.ts +121 -0
- package/src/tui/ui/canvas.ts +96 -0
- package/src/tui/ui/colors.ts +70 -0
- package/src/tui/ui/composer.ts +200 -0
- package/src/tui/ui/control-panel.ts +23 -0
- package/src/tui/ui/dialog.ts +379 -0
- package/src/tui/ui/draft.ts +23 -0
- package/src/tui/ui/edge.ts +186 -0
- package/src/tui/ui/image-size.ts +40 -0
- package/src/tui/ui/ink.ts +210 -0
- package/src/tui/ui/items.ts +40 -0
- package/src/tui/ui/keys.ts +40 -0
- package/src/tui/ui/layout.ts +74 -0
- package/src/tui/ui/list-model.ts +86 -0
- package/src/tui/ui/list-view.ts +172 -0
- package/src/tui/ui/mascot.ts +67 -0
- package/src/tui/ui/messages.ts +518 -0
- package/src/tui/ui/motion.ts +28 -0
- package/src/tui/ui/paths.ts +10 -0
- package/src/tui/ui/pictures.ts +78 -0
- package/src/tui/ui/screen.ts +421 -0
- package/src/tui/ui/status.ts +279 -0
- package/src/tui/ui/styled.ts +85 -0
- package/src/tui/ui/testing.ts +5 -0
- package/src/tui/ui/tool-card.ts +150 -0
- package/src/apps/extension-ui.ts +0 -330
- package/src/apps/resource-browser.ts +0 -75
- package/src/apps/session-browser.ts +0 -113
- package/src/apps/session-picker.ts +0 -55
- package/src/tui/ansi.ts +0 -67
- package/src/tui/autocomplete.ts +0 -29
- package/src/tui/chat-viewport.ts +0 -47
- package/src/tui/complete.ts +0 -87
- package/src/tui/editor.ts +0 -940
- package/src/tui/host.ts +0 -264
- package/src/tui/input.ts +0 -75
- package/src/tui/keys.ts +0 -378
- package/src/tui/markdown.ts +0 -17
- package/src/tui/render.ts +0 -153
- package/src/tui/select.ts +0 -258
- package/src/tui/settings.ts +0 -44
- package/src/tui/statusline.ts +0 -162
- package/src/tui/system-theme.ts +0 -700
- package/src/tui/terminal.ts +0 -30
- package/src/tui/text.ts +0 -52
- package/src/tui/toolview.ts +0 -386
- package/src/tui/transcript.ts +0 -123
- package/src/tui/tree.ts +0 -471
- package/src/vendor/pi-tui/LICENSE.upstream +0 -21
- package/src/vendor/pi-tui/UPSTREAM.json +0 -50
- package/src/vendor/pi-tui/VENDOR.md +0 -25
- package/src/vendor/pi-tui/alt-screen-search.ts +0 -327
- package/src/vendor/pi-tui/autocomplete.ts +0 -860
- package/src/vendor/pi-tui/colors.ts +0 -367
- package/src/vendor/pi-tui/components/alt-screen-flash.ts +0 -51
- package/src/vendor/pi-tui/components/box.ts +0 -166
- package/src/vendor/pi-tui/components/cancellable-loader.ts +0 -40
- package/src/vendor/pi-tui/components/editor.ts +0 -2472
- package/src/vendor/pi-tui/components/h-stack.ts +0 -44
- package/src/vendor/pi-tui/components/image.ts +0 -127
- package/src/vendor/pi-tui/components/input.ts +0 -494
- package/src/vendor/pi-tui/components/loader.ts +0 -101
- package/src/vendor/pi-tui/components/markdown.ts +0 -1021
- package/src/vendor/pi-tui/components/mouse-region.ts +0 -33
- package/src/vendor/pi-tui/components/scroll-view.ts +0 -224
- package/src/vendor/pi-tui/components/select-list.ts +0 -273
- package/src/vendor/pi-tui/components/settings-list.ts +0 -328
- package/src/vendor/pi-tui/components/spacer.ts +0 -28
- package/src/vendor/pi-tui/components/stack.ts +0 -154
- package/src/vendor/pi-tui/components/text.ts +0 -107
- package/src/vendor/pi-tui/components/truncated-text.ts +0 -65
- package/src/vendor/pi-tui/components/v-stack.ts +0 -33
- package/src/vendor/pi-tui/editor-component.ts +0 -74
- package/src/vendor/pi-tui/fuzzy.ts +0 -138
- package/src/vendor/pi-tui/index.ts +0 -186
- package/src/vendor/pi-tui/keybindings.ts +0 -320
- package/src/vendor/pi-tui/keys.ts +0 -1401
- package/src/vendor/pi-tui/kill-ring.ts +0 -46
- package/src/vendor/pi-tui/latex.ts +0 -1506
- package/src/vendor/pi-tui/layout-node.ts +0 -51
- package/src/vendor/pi-tui/layout.ts +0 -449
- package/src/vendor/pi-tui/native/UPSTREAM.json +0 -23
- package/src/vendor/pi-tui/native/clipboard.h +0 -208
- package/src/vendor/pi-tui/native/darwin/README.md +0 -22
- package/src/vendor/pi-tui/native/darwin/build.sh +0 -69
- package/src/vendor/pi-tui/native/darwin/prebuilds/darwin-arm64/darwin-platform.node +0 -0
- package/src/vendor/pi-tui/native/darwin/prebuilds/darwin-x64/darwin-platform.node +0 -0
- package/src/vendor/pi-tui/native/darwin/src/darwin-platform.m +0 -132
- package/src/vendor/pi-tui/native/linux/README.md +0 -23
- package/src/vendor/pi-tui/native/linux/build.sh +0 -65
- package/src/vendor/pi-tui/native/linux/prebuilds/linux-arm64/linux-platform-x11.node +0 -0
- package/src/vendor/pi-tui/native/linux/prebuilds/linux-x64/linux-platform-x11.node +0 -0
- package/src/vendor/pi-tui/native/linux/src/clipboard-worker.h +0 -70
- package/src/vendor/pi-tui/native/linux/src/linux-platform-x11.c +0 -274
- package/src/vendor/pi-tui/native/napi.h +0 -91
- package/src/vendor/pi-tui/native/win32/README.md +0 -31
- package/src/vendor/pi-tui/native/win32/build.mjs +0 -232
- package/src/vendor/pi-tui/native/win32/prebuilds/win32-arm64/win32-platform.node +0 -0
- package/src/vendor/pi-tui/native/win32/prebuilds/win32-x64/win32-platform.node +0 -0
- package/src/vendor/pi-tui/native/win32/src/win32-platform.c +0 -241
- package/src/vendor/pi-tui/native-modifiers.ts +0 -13
- package/src/vendor/pi-tui/native-module-path.ts +0 -31
- package/src/vendor/pi-tui/native-platform.ts +0 -65
- package/src/vendor/pi-tui/oklab.ts +0 -233
- package/src/vendor/pi-tui/stdin-buffer.ts +0 -444
- package/src/vendor/pi-tui/terminal-colors.ts +0 -91
- package/src/vendor/pi-tui/terminal-image.ts +0 -731
- package/src/vendor/pi-tui/terminal.ts +0 -554
- package/src/vendor/pi-tui/tui-alt-screen.ts +0 -1750
- package/src/vendor/pi-tui/tui-main-screen.ts +0 -655
- package/src/vendor/pi-tui/tui.ts +0 -1493
- package/src/vendor/pi-tui/undo-stack.ts +0 -28
- package/src/vendor/pi-tui/utils.ts +0 -1385
- package/src/vendor/pi-tui/wheel-scroll.ts +0 -82
- package/src/vendor/pi-tui/word-navigation.ts +0 -117
|
@@ -1,328 +0,0 @@
|
|
|
1
|
-
import { fuzzyFilter } from "../fuzzy.ts";
|
|
2
|
-
import { getKeybindings } from "../keybindings.ts";
|
|
3
|
-
import type { Component, TuiMouseEvent, TuiMouseEventResult } from "../tui.ts";
|
|
4
|
-
import { truncateToWidth, visibleWidth, wrapTextWithAnsi } from "../utils.ts";
|
|
5
|
-
import { Input } from "./input.ts";
|
|
6
|
-
|
|
7
|
-
export interface SettingItem {
|
|
8
|
-
/** Unique identifier for this setting */
|
|
9
|
-
id: string;
|
|
10
|
-
/** Display label (left side) */
|
|
11
|
-
label: string;
|
|
12
|
-
/** Optional description shown when selected */
|
|
13
|
-
description?: string;
|
|
14
|
-
/** Current value to display (right side) */
|
|
15
|
-
currentValue: string;
|
|
16
|
-
/** If provided, Enter/Space cycles through these values */
|
|
17
|
-
values?: string[];
|
|
18
|
-
/** If provided, Enter opens this submenu. Receives current value and done callback.
|
|
19
|
-
* done() accepts an optional selectedValue and an optional navigateTo id to move the cursor after close. */
|
|
20
|
-
submenu?: (
|
|
21
|
-
currentValue: string,
|
|
22
|
-
done: (selectedValue?: string, options?: { navigateTo?: string }) => void,
|
|
23
|
-
) => Component;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export interface SettingsListTheme {
|
|
27
|
-
label: (text: string, selected: boolean) => string;
|
|
28
|
-
value: (text: string, selected: boolean) => string;
|
|
29
|
-
description: (text: string) => string;
|
|
30
|
-
cursor: string;
|
|
31
|
-
hint: (text: string) => string;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export interface SettingsListOptions {
|
|
35
|
-
enableSearch?: boolean;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export class SettingsList implements Component {
|
|
39
|
-
private items: SettingItem[];
|
|
40
|
-
private filteredItems: SettingItem[];
|
|
41
|
-
private theme: SettingsListTheme;
|
|
42
|
-
private selectedIndex = 0;
|
|
43
|
-
private mousePressedIndex: number | undefined;
|
|
44
|
-
private maxVisible: number;
|
|
45
|
-
private onChange: (id: string, newValue: string) => void;
|
|
46
|
-
private onCancel: () => void;
|
|
47
|
-
private searchInput?: Input;
|
|
48
|
-
private searchEnabled: boolean;
|
|
49
|
-
|
|
50
|
-
// Submenu state
|
|
51
|
-
private submenuComponent: Component | null = null;
|
|
52
|
-
private submenuItemIndex: number | null = null;
|
|
53
|
-
private navigateAfterClose: string | null = null;
|
|
54
|
-
|
|
55
|
-
constructor(
|
|
56
|
-
items: SettingItem[],
|
|
57
|
-
maxVisible: number,
|
|
58
|
-
theme: SettingsListTheme,
|
|
59
|
-
onChange: (id: string, newValue: string) => void,
|
|
60
|
-
onCancel: () => void,
|
|
61
|
-
options: SettingsListOptions = {},
|
|
62
|
-
) {
|
|
63
|
-
this.items = items;
|
|
64
|
-
this.filteredItems = items;
|
|
65
|
-
this.maxVisible = maxVisible;
|
|
66
|
-
this.theme = theme;
|
|
67
|
-
this.onChange = onChange;
|
|
68
|
-
this.onCancel = onCancel;
|
|
69
|
-
this.searchEnabled = options.enableSearch ?? false;
|
|
70
|
-
if (this.searchEnabled) {
|
|
71
|
-
this.searchInput = new Input();
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/** Update an item's currentValue */
|
|
76
|
-
updateValue(id: string, newValue: string): void {
|
|
77
|
-
const item = this.items.find((i) => i.id === id);
|
|
78
|
-
if (item) {
|
|
79
|
-
item.currentValue = newValue;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/** Move selection to the item with the given id (no-op if not found). */
|
|
84
|
-
selectItem(id: string): void {
|
|
85
|
-
const items = this.searchEnabled ? this.filteredItems : this.items;
|
|
86
|
-
const index = items.findIndex((i) => i.id === id);
|
|
87
|
-
if (index !== -1) {
|
|
88
|
-
this.selectedIndex = index;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
invalidate(): void {
|
|
93
|
-
this.submenuComponent?.invalidate?.();
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
render(width: number): string[] {
|
|
97
|
-
// If submenu is active, render it instead
|
|
98
|
-
if (this.submenuComponent) {
|
|
99
|
-
return this.submenuComponent.render(width);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
return this.renderMainList(width);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
private renderMainList(width: number): string[] {
|
|
106
|
-
const lines: string[] = [];
|
|
107
|
-
|
|
108
|
-
if (this.searchEnabled && this.searchInput) {
|
|
109
|
-
lines.push(...this.searchInput.render(width));
|
|
110
|
-
lines.push("");
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
if (this.items.length === 0) {
|
|
114
|
-
lines.push(this.theme.hint(" No settings available"));
|
|
115
|
-
if (this.searchEnabled) {
|
|
116
|
-
this.addHintLine(lines, width);
|
|
117
|
-
}
|
|
118
|
-
return lines;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const displayItems = this.getDisplayItems();
|
|
122
|
-
if (displayItems.length === 0) {
|
|
123
|
-
lines.push(truncateToWidth(this.theme.hint(" No matching settings"), width));
|
|
124
|
-
this.addHintLine(lines, width);
|
|
125
|
-
return lines;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// Calculate visible range with scrolling
|
|
129
|
-
const { startIndex, endIndex } = this.getVisibleRange(displayItems);
|
|
130
|
-
|
|
131
|
-
// Calculate max label width for alignment
|
|
132
|
-
const maxLabelWidth = Math.min(36, Math.max(...this.items.map((item) => visibleWidth(item.label))));
|
|
133
|
-
|
|
134
|
-
// Render visible items
|
|
135
|
-
for (let i = startIndex; i < endIndex; i++) {
|
|
136
|
-
const item = displayItems[i];
|
|
137
|
-
if (!item) continue;
|
|
138
|
-
|
|
139
|
-
const isSelected = i === this.selectedIndex;
|
|
140
|
-
const prefix = isSelected ? this.theme.cursor : " ";
|
|
141
|
-
const prefixWidth = visibleWidth(prefix);
|
|
142
|
-
|
|
143
|
-
// Pad label to align values
|
|
144
|
-
const labelPadded = item.label + " ".repeat(Math.max(0, maxLabelWidth - visibleWidth(item.label)));
|
|
145
|
-
const labelText = this.theme.label(labelPadded, isSelected);
|
|
146
|
-
|
|
147
|
-
// Calculate space for value
|
|
148
|
-
const separator = " ";
|
|
149
|
-
const usedWidth = prefixWidth + maxLabelWidth + visibleWidth(separator);
|
|
150
|
-
const valueMaxWidth = width - usedWidth - 2;
|
|
151
|
-
|
|
152
|
-
const valueText = this.theme.value(truncateToWidth(item.currentValue, valueMaxWidth, ""), isSelected);
|
|
153
|
-
|
|
154
|
-
lines.push(truncateToWidth(prefix + labelText + separator + valueText, width));
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// Add scroll indicator if needed
|
|
158
|
-
if (startIndex > 0 || endIndex < displayItems.length) {
|
|
159
|
-
const scrollText = ` (${this.selectedIndex + 1}/${displayItems.length})`;
|
|
160
|
-
lines.push(this.theme.hint(truncateToWidth(scrollText, width - 2, "")));
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
// Add description for selected item
|
|
164
|
-
const selectedItem = displayItems[this.selectedIndex];
|
|
165
|
-
if (selectedItem?.description) {
|
|
166
|
-
lines.push("");
|
|
167
|
-
const wrappedDesc = wrapTextWithAnsi(selectedItem.description, width - 4);
|
|
168
|
-
for (const line of wrappedDesc) {
|
|
169
|
-
lines.push(this.theme.description(` ${line}`));
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
// Add hint
|
|
174
|
-
this.addHintLine(lines, width);
|
|
175
|
-
|
|
176
|
-
return lines;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
handleMouse(event: TuiMouseEvent): TuiMouseEventResult | undefined {
|
|
180
|
-
if (this.submenuComponent) {
|
|
181
|
-
const result = this.submenuComponent.handleMouse?.(event);
|
|
182
|
-
return result ? { ...result, focus: true } : undefined;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
if (this.searchEnabled && this.searchInput) {
|
|
186
|
-
if (event.y === 0) {
|
|
187
|
-
const result = this.searchInput.handleMouse?.(event);
|
|
188
|
-
return result ? { ...result, focus: true } : undefined;
|
|
189
|
-
}
|
|
190
|
-
if (event.y === 1) return undefined;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
const displayItems = this.getDisplayItems();
|
|
194
|
-
if (displayItems.length === 0) return undefined;
|
|
195
|
-
if (event.type === "wheel" && event.wheelDelta) {
|
|
196
|
-
const delta = event.wheelDelta < 0 ? -1 : 1;
|
|
197
|
-
const previousIndex = this.selectedIndex;
|
|
198
|
-
this.selectedIndex = Math.max(0, Math.min(displayItems.length - 1, this.selectedIndex + delta));
|
|
199
|
-
return { handled: true, render: this.selectedIndex !== previousIndex };
|
|
200
|
-
}
|
|
201
|
-
// Hover must not change selection: the visible range is centered on it.
|
|
202
|
-
if (event.button !== "left" || (event.type !== "press" && event.type !== "click")) return undefined;
|
|
203
|
-
|
|
204
|
-
const rowOffset = this.searchEnabled ? 2 : 0;
|
|
205
|
-
const { startIndex, endIndex } = this.getVisibleRange(displayItems);
|
|
206
|
-
const itemIndex = startIndex + event.y - rowOffset;
|
|
207
|
-
if (itemIndex < startIndex || itemIndex >= endIndex) return undefined;
|
|
208
|
-
if (event.type === "press") {
|
|
209
|
-
this.mousePressedIndex = itemIndex;
|
|
210
|
-
this.selectedIndex = itemIndex;
|
|
211
|
-
return { handled: true, focus: true };
|
|
212
|
-
}
|
|
213
|
-
if (event.type === "click") {
|
|
214
|
-
this.selectedIndex = this.mousePressedIndex ?? itemIndex;
|
|
215
|
-
this.mousePressedIndex = undefined;
|
|
216
|
-
this.activateItem();
|
|
217
|
-
return { handled: true };
|
|
218
|
-
}
|
|
219
|
-
return undefined;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
handleInput(data: string): void {
|
|
223
|
-
// If submenu is active, delegate all input to it
|
|
224
|
-
// The submenu's onCancel (triggered by escape) will call done() which closes it
|
|
225
|
-
if (this.submenuComponent) {
|
|
226
|
-
this.submenuComponent.handleInput?.(data);
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
// Main list input handling
|
|
231
|
-
const kb = getKeybindings();
|
|
232
|
-
const displayItems = this.getDisplayItems();
|
|
233
|
-
if (kb.matches(data, "tui.select.up")) {
|
|
234
|
-
if (displayItems.length === 0) return;
|
|
235
|
-
this.selectedIndex = this.selectedIndex === 0 ? displayItems.length - 1 : this.selectedIndex - 1;
|
|
236
|
-
} else if (kb.matches(data, "tui.select.down")) {
|
|
237
|
-
if (displayItems.length === 0) return;
|
|
238
|
-
this.selectedIndex = this.selectedIndex === displayItems.length - 1 ? 0 : this.selectedIndex + 1;
|
|
239
|
-
} else if (
|
|
240
|
-
kb.matches(data, "tui.select.confirm") ||
|
|
241
|
-
(data === " " && (!this.searchEnabled || this.searchInput?.getValue().length === 0))
|
|
242
|
-
) {
|
|
243
|
-
this.activateItem();
|
|
244
|
-
} else if (kb.matches(data, "tui.select.cancel")) {
|
|
245
|
-
this.onCancel();
|
|
246
|
-
} else if (this.searchEnabled && this.searchInput) {
|
|
247
|
-
this.searchInput.handleInput(data);
|
|
248
|
-
this.applyFilter(this.searchInput.getValue());
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
private getDisplayItems(): SettingItem[] {
|
|
253
|
-
return this.searchEnabled ? this.filteredItems : this.items;
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
private getVisibleRange(displayItems: readonly SettingItem[]): { startIndex: number; endIndex: number } {
|
|
257
|
-
const startIndex = Math.max(
|
|
258
|
-
0,
|
|
259
|
-
Math.min(this.selectedIndex - Math.floor(this.maxVisible / 2), displayItems.length - this.maxVisible),
|
|
260
|
-
);
|
|
261
|
-
return { startIndex, endIndex: Math.min(startIndex + this.maxVisible, displayItems.length) };
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
private activateItem(): void {
|
|
265
|
-
const item = this.getDisplayItems()[this.selectedIndex];
|
|
266
|
-
if (!item) return;
|
|
267
|
-
|
|
268
|
-
if (item.submenu) {
|
|
269
|
-
// Open submenu, passing current value so it can pre-select correctly
|
|
270
|
-
this.submenuItemIndex = this.selectedIndex;
|
|
271
|
-
this.submenuComponent = item.submenu(
|
|
272
|
-
item.currentValue,
|
|
273
|
-
(selectedValue?: string, options?: { navigateTo?: string }) => {
|
|
274
|
-
if (selectedValue !== undefined) {
|
|
275
|
-
item.currentValue = selectedValue;
|
|
276
|
-
this.onChange(item.id, selectedValue);
|
|
277
|
-
}
|
|
278
|
-
if (options?.navigateTo) {
|
|
279
|
-
this.navigateAfterClose = options.navigateTo;
|
|
280
|
-
}
|
|
281
|
-
this.closeSubmenu();
|
|
282
|
-
},
|
|
283
|
-
);
|
|
284
|
-
} else if (item.values && item.values.length > 0) {
|
|
285
|
-
// Cycle through values
|
|
286
|
-
const currentIndex = item.values.indexOf(item.currentValue);
|
|
287
|
-
const nextIndex = (currentIndex + 1) % item.values.length;
|
|
288
|
-
const newValue = item.values[nextIndex];
|
|
289
|
-
item.currentValue = newValue;
|
|
290
|
-
this.onChange(item.id, newValue);
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
private closeSubmenu(): void {
|
|
295
|
-
this.submenuComponent = null;
|
|
296
|
-
if (this.navigateAfterClose !== null) {
|
|
297
|
-
const id = this.navigateAfterClose;
|
|
298
|
-
this.navigateAfterClose = null;
|
|
299
|
-
this.submenuItemIndex = null;
|
|
300
|
-
this.selectItem(id);
|
|
301
|
-
// Open the target item's submenu automatically
|
|
302
|
-
this.activateItem();
|
|
303
|
-
} else if (this.submenuItemIndex !== null) {
|
|
304
|
-
// Restore selection to the item that opened the submenu
|
|
305
|
-
this.selectedIndex = this.submenuItemIndex;
|
|
306
|
-
this.submenuItemIndex = null;
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
private applyFilter(query: string): void {
|
|
311
|
-
this.filteredItems = fuzzyFilter(this.items, query, (item) => item.label);
|
|
312
|
-
this.selectedIndex = 0;
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
private addHintLine(lines: string[], width: number): void {
|
|
316
|
-
lines.push("");
|
|
317
|
-
lines.push(
|
|
318
|
-
truncateToWidth(
|
|
319
|
-
this.theme.hint(
|
|
320
|
-
this.searchEnabled
|
|
321
|
-
? " Type to search · Enter/Space to change · Esc to cancel"
|
|
322
|
-
: " Enter/Space to change · Esc to cancel",
|
|
323
|
-
),
|
|
324
|
-
width,
|
|
325
|
-
),
|
|
326
|
-
);
|
|
327
|
-
}
|
|
328
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { Component } from "../tui.ts";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Spacer component that renders empty lines
|
|
5
|
-
*/
|
|
6
|
-
export class Spacer implements Component {
|
|
7
|
-
private lines: number;
|
|
8
|
-
|
|
9
|
-
constructor(lines: number = 1) {
|
|
10
|
-
this.lines = lines;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
setLines(lines: number): void {
|
|
14
|
-
this.lines = lines;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
invalidate(): void {
|
|
18
|
-
// No cached state to invalidate currently
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
render(_width: number): string[] {
|
|
22
|
-
const result: string[] = [];
|
|
23
|
-
for (let i = 0; i < this.lines; i++) {
|
|
24
|
-
result.push("");
|
|
25
|
-
}
|
|
26
|
-
return result;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import { LAYOUT_NODE, type LayoutViewport, type StackLayoutEntry, type StackLayoutNode } from "../layout-node.ts";
|
|
2
|
-
import { type Component, Container } from "../tui.ts";
|
|
3
|
-
|
|
4
|
-
export interface StackEntryOptions {
|
|
5
|
-
basis?: number | "auto";
|
|
6
|
-
grow?: number;
|
|
7
|
-
shrink?: number;
|
|
8
|
-
minSize?: number;
|
|
9
|
-
maxSize?: number;
|
|
10
|
-
visible?: (viewport: LayoutViewport) => boolean;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export interface StackEntry extends StackEntryOptions {
|
|
14
|
-
component: Component;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export type StackChild = Component | StackEntry;
|
|
18
|
-
|
|
19
|
-
export interface StackOptions {
|
|
20
|
-
gap?: number;
|
|
21
|
-
align?: "stretch" | "start" | "center" | "end";
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function isStackEntry(child: StackChild): child is StackEntry {
|
|
25
|
-
return !("render" in child);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function normalizeSize(value: number | undefined, fallback: number): number {
|
|
29
|
-
return value === undefined || !Number.isFinite(value) ? fallback : Math.max(0, Math.floor(value));
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export abstract class Stack extends Container {
|
|
33
|
-
protected readonly entries: StackLayoutEntry[] = [];
|
|
34
|
-
protected readonly gap: number;
|
|
35
|
-
protected readonly align: "stretch" | "start" | "center" | "end";
|
|
36
|
-
protected abstract readonly layoutType: "vstack" | "hstack";
|
|
37
|
-
|
|
38
|
-
constructor(children: StackChild[] = [], options: StackOptions = {}) {
|
|
39
|
-
super();
|
|
40
|
-
this.gap = normalizeSize(options.gap, 0);
|
|
41
|
-
this.align = options.align ?? "stretch";
|
|
42
|
-
for (const child of children) {
|
|
43
|
-
if (isStackEntry(child)) this.addChild(child.component, child);
|
|
44
|
-
else this.addChild(child);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
override addChild(component: Component, options: StackEntryOptions = {}): void {
|
|
49
|
-
super.addChild(component);
|
|
50
|
-
this.entries.push({
|
|
51
|
-
component,
|
|
52
|
-
...(options.basis === undefined ? {} : { basis: options.basis }),
|
|
53
|
-
...(options.grow === undefined ? {} : { grow: normalizeSize(options.grow, 0) }),
|
|
54
|
-
...(options.shrink === undefined ? {} : { shrink: normalizeSize(options.shrink, 1) }),
|
|
55
|
-
...(options.minSize === undefined ? {} : { minSize: normalizeSize(options.minSize, 0) }),
|
|
56
|
-
...(options.maxSize === undefined ? {} : { maxSize: normalizeSize(options.maxSize, Number.MAX_SAFE_INTEGER) }),
|
|
57
|
-
...(options.visible === undefined ? {} : { visible: options.visible }),
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
override removeChild(component: Component): void {
|
|
62
|
-
super.removeChild(component);
|
|
63
|
-
const index = this.entries.findIndex((entry) => entry.component === component);
|
|
64
|
-
if (index !== -1) this.entries.splice(index, 1);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
override clear(): void {
|
|
68
|
-
super.clear();
|
|
69
|
-
this.entries.length = 0;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
[LAYOUT_NODE](): StackLayoutNode {
|
|
73
|
-
return {
|
|
74
|
-
type: this.layoutType,
|
|
75
|
-
entries: this.entries,
|
|
76
|
-
gap: this.gap,
|
|
77
|
-
align: this.align,
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export function visibleStackEntries(
|
|
83
|
-
entries: readonly StackLayoutEntry[],
|
|
84
|
-
viewport: LayoutViewport,
|
|
85
|
-
): StackLayoutEntry[] {
|
|
86
|
-
return entries.filter((entry) => entry.visible?.(viewport) ?? true);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function clampSize(size: number, entry: StackLayoutEntry): number {
|
|
90
|
-
const min = Math.max(0, Math.floor(entry.minSize ?? 0));
|
|
91
|
-
const max = Math.max(min, Math.floor(entry.maxSize ?? Number.MAX_SAFE_INTEGER));
|
|
92
|
-
return Math.max(min, Math.min(max, Math.max(0, Math.floor(size))));
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
function distribute(
|
|
96
|
-
sizes: number[],
|
|
97
|
-
entries: readonly StackLayoutEntry[],
|
|
98
|
-
amount: number,
|
|
99
|
-
mode: "grow" | "shrink",
|
|
100
|
-
): void {
|
|
101
|
-
let remaining = amount;
|
|
102
|
-
while (remaining > 0) {
|
|
103
|
-
const candidates = entries
|
|
104
|
-
.map((entry, index) => ({ entry, index }))
|
|
105
|
-
.filter(({ entry, index }) => {
|
|
106
|
-
if (mode === "grow") {
|
|
107
|
-
return (entry.grow ?? 0) > 0 && sizes[index]! < (entry.maxSize ?? Number.MAX_SAFE_INTEGER);
|
|
108
|
-
}
|
|
109
|
-
return (entry.shrink ?? 1) > 0 && sizes[index]! > (entry.minSize ?? 0);
|
|
110
|
-
});
|
|
111
|
-
if (candidates.length === 0) return;
|
|
112
|
-
|
|
113
|
-
const totalWeight = candidates.reduce((sum, { entry, index }) => {
|
|
114
|
-
return sum + (mode === "grow" ? (entry.grow ?? 0) : (entry.shrink ?? 1) * Math.max(1, sizes[index]!));
|
|
115
|
-
}, 0);
|
|
116
|
-
let distributed = 0;
|
|
117
|
-
for (const { entry, index } of candidates) {
|
|
118
|
-
if (remaining <= 0) break;
|
|
119
|
-
const weight = mode === "grow" ? (entry.grow ?? 0) : (entry.shrink ?? 1) * Math.max(1, sizes[index]!);
|
|
120
|
-
const proposed = Math.max(1, Math.floor((remaining * weight) / totalWeight));
|
|
121
|
-
const capacity =
|
|
122
|
-
mode === "grow"
|
|
123
|
-
? (entry.maxSize ?? Number.MAX_SAFE_INTEGER) - sizes[index]!
|
|
124
|
-
: sizes[index]! - (entry.minSize ?? 0);
|
|
125
|
-
const delta = Math.min(remaining, proposed, capacity);
|
|
126
|
-
if (delta <= 0) continue;
|
|
127
|
-
sizes[index] = sizes[index]! + (mode === "grow" ? delta : -delta);
|
|
128
|
-
remaining -= delta;
|
|
129
|
-
distributed += delta;
|
|
130
|
-
}
|
|
131
|
-
if (distributed === 0) return;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
export function allocateStackSizes(
|
|
136
|
-
entries: readonly StackLayoutEntry[],
|
|
137
|
-
intrinsicSizes: readonly number[],
|
|
138
|
-
availableSize: number | undefined,
|
|
139
|
-
gap: number,
|
|
140
|
-
): number[] {
|
|
141
|
-
const sizes = entries.map((entry, index) =>
|
|
142
|
-
clampSize(
|
|
143
|
-
entry.basis === undefined || entry.basis === "auto" ? (intrinsicSizes[index] ?? 0) : entry.basis,
|
|
144
|
-
entry,
|
|
145
|
-
),
|
|
146
|
-
);
|
|
147
|
-
if (availableSize === undefined) return sizes;
|
|
148
|
-
|
|
149
|
-
const contentSize = Math.max(0, Math.floor(availableSize) - Math.max(0, entries.length - 1) * gap);
|
|
150
|
-
const total = sizes.reduce((sum, size) => sum + size, 0);
|
|
151
|
-
if (total < contentSize) distribute(sizes, entries, contentSize - total, "grow");
|
|
152
|
-
else if (total > contentSize) distribute(sizes, entries, total - contentSize, "shrink");
|
|
153
|
-
return sizes;
|
|
154
|
-
}
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import type { Component } from "../tui.ts";
|
|
2
|
-
import { applyBackgroundToLine, visibleWidth, wrapTextWithAnsi } from "../utils.ts";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Text component - displays multi-line text with word wrapping
|
|
6
|
-
*/
|
|
7
|
-
export class Text implements Component {
|
|
8
|
-
private text: string;
|
|
9
|
-
private paddingX: number; // Left/right padding
|
|
10
|
-
private paddingY: number; // Top/bottom padding
|
|
11
|
-
private customBgFn?: (text: string) => string;
|
|
12
|
-
|
|
13
|
-
// Cache for rendered output
|
|
14
|
-
private cachedText?: string;
|
|
15
|
-
private cachedWidth?: number;
|
|
16
|
-
private cachedLines?: string[];
|
|
17
|
-
|
|
18
|
-
constructor(text: string = "", paddingX: number = 1, paddingY: number = 1, customBgFn?: (text: string) => string) {
|
|
19
|
-
this.text = text;
|
|
20
|
-
this.paddingX = paddingX;
|
|
21
|
-
this.paddingY = paddingY;
|
|
22
|
-
this.customBgFn = customBgFn;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
setText(text: string): void {
|
|
26
|
-
this.text = text;
|
|
27
|
-
this.cachedText = undefined;
|
|
28
|
-
this.cachedWidth = undefined;
|
|
29
|
-
this.cachedLines = undefined;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
setCustomBgFn(customBgFn?: (text: string) => string): void {
|
|
33
|
-
this.customBgFn = customBgFn;
|
|
34
|
-
this.cachedText = undefined;
|
|
35
|
-
this.cachedWidth = undefined;
|
|
36
|
-
this.cachedLines = undefined;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
invalidate(): void {
|
|
40
|
-
this.cachedText = undefined;
|
|
41
|
-
this.cachedWidth = undefined;
|
|
42
|
-
this.cachedLines = undefined;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
render(width: number): string[] {
|
|
46
|
-
// Check cache
|
|
47
|
-
if (this.cachedLines && this.cachedText === this.text && this.cachedWidth === width) {
|
|
48
|
-
return this.cachedLines;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// Don't render anything if there's no actual text
|
|
52
|
-
if (!this.text || this.text.trim() === "") {
|
|
53
|
-
const result: string[] = [];
|
|
54
|
-
this.cachedText = this.text;
|
|
55
|
-
this.cachedWidth = width;
|
|
56
|
-
this.cachedLines = result;
|
|
57
|
-
return result;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// Replace tabs with 3 spaces
|
|
61
|
-
const normalizedText = this.text.replace(/\t/g, " ");
|
|
62
|
-
|
|
63
|
-
// Reduce margins when necessary so content and padding fit within the available width.
|
|
64
|
-
const paddingX = Math.min(this.paddingX, Math.max(0, Math.floor((width - 1) / 2)));
|
|
65
|
-
const contentWidth = Math.max(1, width - paddingX * 2);
|
|
66
|
-
|
|
67
|
-
// Wrap text (this preserves ANSI codes but does NOT pad)
|
|
68
|
-
const wrappedLines = wrapTextWithAnsi(normalizedText, contentWidth);
|
|
69
|
-
|
|
70
|
-
// Add margins and background to each line
|
|
71
|
-
const leftMargin = " ".repeat(paddingX);
|
|
72
|
-
const rightMargin = " ".repeat(paddingX);
|
|
73
|
-
const contentLines: string[] = [];
|
|
74
|
-
|
|
75
|
-
for (const line of wrappedLines) {
|
|
76
|
-
// Add margins
|
|
77
|
-
const lineWithMargins = leftMargin + line + rightMargin;
|
|
78
|
-
|
|
79
|
-
// Apply background if specified (this also pads to full width)
|
|
80
|
-
if (this.customBgFn) {
|
|
81
|
-
contentLines.push(applyBackgroundToLine(lineWithMargins, width, this.customBgFn));
|
|
82
|
-
} else {
|
|
83
|
-
// No background - just pad to width with spaces
|
|
84
|
-
const visibleLen = visibleWidth(lineWithMargins);
|
|
85
|
-
const paddingNeeded = Math.max(0, width - visibleLen);
|
|
86
|
-
contentLines.push(lineWithMargins + " ".repeat(paddingNeeded));
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// Add top/bottom padding (empty lines)
|
|
91
|
-
const emptyLine = " ".repeat(width);
|
|
92
|
-
const emptyLines: string[] = [];
|
|
93
|
-
for (let i = 0; i < this.paddingY; i++) {
|
|
94
|
-
const line = this.customBgFn ? applyBackgroundToLine(emptyLine, width, this.customBgFn) : emptyLine;
|
|
95
|
-
emptyLines.push(line);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const result = [...emptyLines, ...contentLines, ...emptyLines];
|
|
99
|
-
|
|
100
|
-
// Update cache
|
|
101
|
-
this.cachedText = this.text;
|
|
102
|
-
this.cachedWidth = width;
|
|
103
|
-
this.cachedLines = result;
|
|
104
|
-
|
|
105
|
-
return result.length > 0 ? result : [""];
|
|
106
|
-
}
|
|
107
|
-
}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import type { Component } from "../tui.ts";
|
|
2
|
-
import { truncateToWidth, visibleWidth } from "../utils.ts";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Text component that truncates to fit viewport width
|
|
6
|
-
*/
|
|
7
|
-
export class TruncatedText implements Component {
|
|
8
|
-
private text: string;
|
|
9
|
-
private paddingX: number;
|
|
10
|
-
private paddingY: number;
|
|
11
|
-
|
|
12
|
-
constructor(text: string, paddingX: number = 0, paddingY: number = 0) {
|
|
13
|
-
this.text = text;
|
|
14
|
-
this.paddingX = paddingX;
|
|
15
|
-
this.paddingY = paddingY;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
invalidate(): void {
|
|
19
|
-
// No cached state to invalidate currently
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
render(width: number): string[] {
|
|
23
|
-
const result: string[] = [];
|
|
24
|
-
|
|
25
|
-
// Empty line padded to width
|
|
26
|
-
const emptyLine = " ".repeat(width);
|
|
27
|
-
|
|
28
|
-
// Add vertical padding above
|
|
29
|
-
for (let i = 0; i < this.paddingY; i++) {
|
|
30
|
-
result.push(emptyLine);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// Calculate available width after horizontal padding
|
|
34
|
-
const availableWidth = Math.max(1, width - this.paddingX * 2);
|
|
35
|
-
|
|
36
|
-
// Take only the first line (stop at newline)
|
|
37
|
-
let singleLineText = this.text;
|
|
38
|
-
const newlineIndex = this.text.indexOf("\n");
|
|
39
|
-
if (newlineIndex !== -1) {
|
|
40
|
-
singleLineText = this.text.substring(0, newlineIndex);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// Truncate text if needed (accounting for ANSI codes)
|
|
44
|
-
const displayText = truncateToWidth(singleLineText, availableWidth);
|
|
45
|
-
|
|
46
|
-
// Add horizontal padding
|
|
47
|
-
const leftPadding = " ".repeat(this.paddingX);
|
|
48
|
-
const rightPadding = " ".repeat(this.paddingX);
|
|
49
|
-
const lineWithPadding = leftPadding + displayText + rightPadding;
|
|
50
|
-
|
|
51
|
-
// Pad line to exactly width characters
|
|
52
|
-
const lineVisibleWidth = visibleWidth(lineWithPadding);
|
|
53
|
-
const paddingNeeded = Math.max(0, width - lineVisibleWidth);
|
|
54
|
-
const finalLine = lineWithPadding + " ".repeat(paddingNeeded);
|
|
55
|
-
|
|
56
|
-
result.push(finalLine);
|
|
57
|
-
|
|
58
|
-
// Add vertical padding below
|
|
59
|
-
for (let i = 0; i < this.paddingY; i++) {
|
|
60
|
-
result.push(emptyLine);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return result;
|
|
64
|
-
}
|
|
65
|
-
}
|