@agi-fans/dsh-tui 0.21.0 → 0.22.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/lib/CHANGELOG.md +158 -1
- package/lib/chrome/box.d.ts +47 -16
- package/lib/chrome/box.js +172 -130
- package/lib/chrome/box.js.map +1 -1
- package/lib/chrome/code-highlight.d.ts +15 -0
- package/lib/chrome/code-highlight.js +60 -4
- package/lib/chrome/code-highlight.js.map +1 -1
- package/lib/chrome/command-output.d.ts +29 -2
- package/lib/chrome/command-output.js +100 -4
- package/lib/chrome/command-output.js.map +1 -1
- package/lib/chrome/main-screen-renderer.d.ts +16 -0
- package/lib/chrome/main-screen-renderer.js +53 -5
- package/lib/chrome/main-screen-renderer.js.map +1 -1
- package/lib/chrome/markdown.js +30 -10
- package/lib/chrome/markdown.js.map +1 -1
- package/lib/chrome/relative-time.d.ts +17 -0
- package/lib/chrome/relative-time.js +36 -0
- package/lib/chrome/relative-time.js.map +1 -1
- package/lib/chrome/secret-mask.d.ts +35 -0
- package/lib/chrome/secret-mask.js +180 -0
- package/lib/chrome/secret-mask.js.map +1 -0
- package/lib/chrome/status-config.d.ts +161 -51
- package/lib/chrome/status-config.js +237 -126
- package/lib/chrome/status-config.js.map +1 -1
- package/lib/chrome/status-line.d.ts +3 -2
- package/lib/chrome/status-line.js +105 -63
- package/lib/chrome/status-line.js.map +1 -1
- package/lib/chrome/terminal-colors.d.ts +85 -0
- package/lib/chrome/terminal-colors.js +230 -0
- package/lib/chrome/terminal-colors.js.map +1 -0
- package/lib/chrome/terminal-images.d.ts +9 -1
- package/lib/chrome/terminal-images.js +27 -4
- package/lib/chrome/terminal-images.js.map +1 -1
- package/lib/chrome/theme.d.ts +32 -9
- package/lib/chrome/theme.js +595 -498
- package/lib/chrome/theme.js.map +1 -1
- package/lib/chrome/tool-renderers.js +69 -13
- package/lib/chrome/tool-renderers.js.map +1 -1
- package/lib/chrome/tools-list.d.ts +1 -4
- package/lib/chrome/tools-list.js +1 -41
- package/lib/chrome/tools-list.js.map +1 -1
- package/lib/chrome/welcome-tips.d.ts +20 -8
- package/lib/chrome/welcome-tips.js +22 -42
- package/lib/chrome/welcome-tips.js.map +1 -1
- package/lib/commands/auth-ids.d.ts +25 -0
- package/lib/commands/auth-ids.js +27 -0
- package/lib/commands/auth-ids.js.map +1 -0
- package/lib/commands/auth-input.d.ts +34 -0
- package/lib/commands/auth-input.js +96 -0
- package/lib/commands/auth-input.js.map +1 -0
- package/lib/commands/auth-providers.d.ts +39 -0
- package/lib/commands/auth-providers.js +125 -0
- package/lib/commands/auth-providers.js.map +1 -0
- package/lib/commands/auth.d.ts +12 -20
- package/lib/commands/auth.js +42 -229
- package/lib/commands/auth.js.map +1 -1
- package/lib/commands/btw.d.ts +13 -1
- package/lib/commands/btw.js +37 -104
- package/lib/commands/btw.js.map +1 -1
- package/lib/commands/diff.js +1 -96
- package/lib/commands/diff.js.map +1 -1
- package/lib/commands/export.d.ts +1 -1
- package/lib/commands/export.js +3 -27
- package/lib/commands/export.js.map +1 -1
- package/lib/commands/files.d.ts +17 -1
- package/lib/commands/files.js +67 -107
- package/lib/commands/files.js.map +1 -1
- package/lib/commands/jobs.d.ts +19 -4
- package/lib/commands/jobs.js +50 -7
- package/lib/commands/jobs.js.map +1 -1
- package/lib/commands/model.js +108 -76
- package/lib/commands/model.js.map +1 -1
- package/lib/commands/permission.js +15 -16
- package/lib/commands/permission.js.map +1 -1
- package/lib/commands/plugins.js +133 -16
- package/lib/commands/plugins.js.map +1 -1
- package/lib/commands/schedule.d.ts +10 -0
- package/lib/commands/schedule.js +45 -14
- package/lib/commands/schedule.js.map +1 -1
- package/lib/commands/session-configuration.js +2 -10
- package/lib/commands/session-configuration.js.map +1 -1
- package/lib/commands/session.js +14 -38
- package/lib/commands/session.js.map +1 -1
- package/lib/commands/terminal.d.ts +14 -8
- package/lib/commands/terminal.js +19 -178
- package/lib/commands/terminal.js.map +1 -1
- package/lib/commands/trajectory.js +4 -1
- package/lib/commands/trajectory.js.map +1 -1
- package/lib/definition.d.ts +122 -22
- package/lib/definition.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/input/actions.d.ts +51 -0
- package/lib/input/actions.js +120 -0
- package/lib/input/actions.js.map +1 -0
- package/lib/input/editor.d.ts +0 -10
- package/lib/input/editor.js +11 -9
- package/lib/input/editor.js.map +1 -1
- package/lib/input/image-paste.d.ts +19 -1
- package/lib/input/image-paste.js +82 -1
- package/lib/input/image-paste.js.map +1 -1
- package/lib/input/keybindings-config.d.ts +12 -5
- package/lib/input/keybindings-config.js +30 -57
- package/lib/input/keybindings-config.js.map +1 -1
- package/lib/input/keys.d.ts +16 -0
- package/lib/input/keys.js +38 -3
- package/lib/input/keys.js.map +1 -1
- package/lib/input/wheel-scroll.d.ts +46 -0
- package/lib/input/wheel-scroll.js +69 -0
- package/lib/input/wheel-scroll.js.map +1 -0
- package/lib/prompt-intents.d.ts +182 -0
- package/lib/prompt-intents.js +127 -0
- package/lib/prompt-intents.js.map +1 -0
- package/lib/runtime/cancellable.d.ts +75 -0
- package/lib/runtime/cancellable.js +76 -0
- package/lib/runtime/cancellable.js.map +1 -0
- package/lib/runtime/composer-images.js +5 -4
- package/lib/runtime/composer-images.js.map +1 -1
- package/lib/runtime/composer-shell.d.ts +17 -2
- package/lib/runtime/composer-shell.js +109 -43
- package/lib/runtime/composer-shell.js.map +1 -1
- package/lib/runtime/file-recovery-review.d.ts +0 -1
- package/lib/runtime/file-recovery-review.js +29 -30
- package/lib/runtime/file-recovery-review.js.map +1 -1
- package/lib/runtime/file-recovery-store.js +5 -1
- package/lib/runtime/file-recovery-store.js.map +1 -1
- package/lib/runtime/file-review.js +1 -1
- package/lib/runtime/file-review.js.map +1 -1
- package/lib/runtime/hook-settings.d.ts +2 -2
- package/lib/runtime/plain-tui.d.ts +2 -0
- package/lib/runtime/plain-tui.js +7 -1
- package/lib/runtime/plain-tui.js.map +1 -1
- package/lib/runtime/plugin-settings.d.ts +1 -1
- package/lib/runtime/plugin-settings.js +10 -8
- package/lib/runtime/plugin-settings.js.map +1 -1
- package/lib/runtime/provider-local.d.ts +57 -15
- package/lib/runtime/provider-local.js +1112 -471
- package/lib/runtime/provider-local.js.map +1 -1
- package/lib/runtime/runner.js +5 -11
- package/lib/runtime/runner.js.map +1 -1
- package/lib/runtime/settings-preferences.js +1 -1
- package/lib/runtime/settings-preferences.js.map +1 -1
- package/lib/runtime/startup-notices.js +2 -0
- package/lib/runtime/startup-notices.js.map +1 -1
- package/lib/runtime/terminal-modes.d.ts +47 -0
- package/lib/runtime/terminal-modes.js +86 -0
- package/lib/runtime/terminal-modes.js.map +1 -0
- package/lib/runtime/terminal-notifications.d.ts +3 -5
- package/lib/runtime/terminal-notifications.js +4 -8
- package/lib/runtime/terminal-notifications.js.map +1 -1
- package/lib/runtime/terminal-probe.d.ts +36 -0
- package/lib/runtime/terminal-probe.js +37 -0
- package/lib/runtime/terminal-probe.js.map +1 -0
- package/lib/runtime/terminal-session.d.ts +57 -0
- package/lib/runtime/terminal-session.js +164 -0
- package/lib/runtime/terminal-session.js.map +1 -0
- package/lib/session/interaction-adapter.js +7 -8
- package/lib/session/interaction-adapter.js.map +1 -1
- package/lib/session/message-queue.js +1 -1
- package/lib/session/message-queue.js.map +1 -1
- package/lib/session/package-metadata.d.ts +8 -0
- package/lib/session/package-metadata.js +8 -0
- package/lib/session/package-metadata.js.map +1 -1
- package/lib/session/session-controller.d.ts +10 -11
- package/lib/session/session-controller.js +95 -13
- package/lib/session/session-controller.js.map +1 -1
- package/lib/session/session-tree.d.ts +2 -0
- package/lib/session/session-tree.js +2 -0
- package/lib/session/session-tree.js.map +1 -1
- package/lib/session/tui-settings.d.ts +40 -11
- package/lib/session/tui-settings.js +73 -34
- package/lib/session/tui-settings.js.map +1 -1
- package/lib/views/autocomplete.d.ts +18 -2
- package/lib/views/autocomplete.js +51 -38
- package/lib/views/autocomplete.js.map +1 -1
- package/lib/views/copy-targets.d.ts +12 -13
- package/lib/views/copy-targets.js +16 -46
- package/lib/views/copy-targets.js.map +1 -1
- package/lib/views/document-reader.js +18 -5
- package/lib/views/document-reader.js.map +1 -1
- package/lib/views/event-views.js +42 -6
- package/lib/views/event-views.js.map +1 -1
- package/lib/views/history-search.js +15 -21
- package/lib/views/history-search.js.map +1 -1
- package/lib/views/hotkeys.d.ts +7 -1
- package/lib/views/hotkeys.js +49 -25
- package/lib/views/hotkeys.js.map +1 -1
- package/lib/views/list-navigation.d.ts +62 -0
- package/lib/views/list-navigation.js +73 -0
- package/lib/views/list-navigation.js.map +1 -0
- package/lib/views/list-view.d.ts +99 -0
- package/lib/views/list-view.js +165 -0
- package/lib/views/list-view.js.map +1 -0
- package/lib/views/prompt-selector.d.ts +31 -3
- package/lib/views/prompt-selector.js +249 -125
- package/lib/views/prompt-selector.js.map +1 -1
- package/lib/views/session-files.d.ts +1 -2
- package/lib/views/session-files.js +1 -11
- package/lib/views/session-files.js.map +1 -1
- package/lib/views/settings-list.d.ts +10 -8
- package/lib/views/settings-list.js +116 -283
- package/lib/views/settings-list.js.map +1 -1
- package/lib/views/trajectory-timeline.d.ts +72 -0
- package/lib/views/trajectory-timeline.js +133 -0
- package/lib/views/trajectory-timeline.js.map +1 -0
- package/lib/views/trajectory.d.ts +15 -4
- package/lib/views/trajectory.js +557 -123
- package/lib/views/trajectory.js.map +1 -1
- package/lib/views/transcript-render.d.ts +95 -25
- package/lib/views/transcript-render.js +501 -167
- package/lib/views/transcript-render.js.map +1 -1
- package/lib/views/transcript-search.d.ts +39 -6
- package/lib/views/transcript-search.js +46 -11
- package/lib/views/transcript-search.js.map +1 -1
- package/lib/views/transcript-types.d.ts +63 -5
- package/lib/views/transcript-types.js +23 -11
- package/lib/views/transcript-types.js.map +1 -1
- package/package.json +67 -86
- package/lib/commands/advisor.d.ts +0 -15
- package/lib/commands/advisor.js +0 -200
- package/lib/commands/advisor.js.map +0 -1
- package/lib/commands/loop.d.ts +0 -52
- package/lib/commands/loop.js +0 -307
- package/lib/commands/loop.js.map +0 -1
- package/lib/commands/rate.d.ts +0 -33
- package/lib/commands/rate.js +0 -212
- package/lib/commands/rate.js.map +0 -1
- package/lib/commands/steer.d.ts +0 -5
- package/lib/commands/steer.js +0 -24
- package/lib/commands/steer.js.map +0 -1
- package/lib/commands/worktree.d.ts +0 -5
- package/lib/commands/worktree.js +0 -103
- package/lib/commands/worktree.js.map +0 -1
- package/lib/runtime/terminal-reader.d.ts +0 -11
- package/lib/runtime/terminal-reader.js +0 -87
- package/lib/runtime/terminal-reader.js.map +0 -1
- package/lib/views/agent-hub.d.ts +0 -32
- package/lib/views/agent-hub.js +0 -209
- package/lib/views/agent-hub.js.map +0 -1
- package/lib/views/copy-selector.d.ts +0 -54
- package/lib/views/copy-selector.js +0 -170
- package/lib/views/copy-selector.js.map +0 -1
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Colors the terminal reports about itself (OSC 10 foreground, OSC 11
|
|
3
|
+
* background, OSC 4 palette entries, CSI ?997 color scheme) and the perceptual
|
|
4
|
+
* math used to adapt a palette to them.
|
|
5
|
+
*
|
|
6
|
+
* A terminal only answers these when it is interactive and willing; every
|
|
7
|
+
* helper here is pure so a caller can probe once, keep whatever arrived, and
|
|
8
|
+
* fall back to the shipped palettes when nothing did.
|
|
9
|
+
* @module @agi-fans/dsh-tui/terminal-colors
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Query the default foreground, background and all sixteen palette entries.
|
|
13
|
+
* `ST` terminates instead of `BEL` because a query is written before the
|
|
14
|
+
* terminal has proven it understands either form.
|
|
15
|
+
*/
|
|
16
|
+
export const COLOR_QUERY = '\x1b]10;?\x1b\\\x1b]11;?\x1b\\'
|
|
17
|
+
+ Array.from({ length: 16 }, (_, index) => `\x1b]4;${index};?\x1b\\`).join('');
|
|
18
|
+
/** Query whether the terminal considers itself dark or light (CSI ?997). */
|
|
19
|
+
export const COLOR_SCHEME_QUERY = '\x1b[?997;?n';
|
|
20
|
+
const OSC_COLOR_REPLY = /^(?:1([01])|4;(\d{1,3}));(.+)$/u;
|
|
21
|
+
const HEX6 = /^#([0-9a-f]{6})$/iu;
|
|
22
|
+
const HEX12 = /^#([0-9a-f]{12})$/iu;
|
|
23
|
+
const RGB_SPEC = /^rgba?:([0-9a-f]{1,4})\/([0-9a-f]{1,4})\/([0-9a-f]{1,4})$/iu;
|
|
24
|
+
function channel(hex) {
|
|
25
|
+
return Math.round((Number.parseInt(hex, 16) / (16 ** hex.length - 1)) * 255);
|
|
26
|
+
}
|
|
27
|
+
/** Parse one OSC 10/11/4 reply body (the text between the introducer and the terminator). */
|
|
28
|
+
export function parseOscColorReply(body) {
|
|
29
|
+
const match = OSC_COLOR_REPLY.exec(body);
|
|
30
|
+
if (match === null)
|
|
31
|
+
return undefined;
|
|
32
|
+
const target = match[1] === '0' ? 'foreground'
|
|
33
|
+
: match[1] === '1' ? 'background'
|
|
34
|
+
: Number.parseInt(match[2] ?? '', 10);
|
|
35
|
+
if (typeof target === 'number' && !(target >= 0 && target <= 15))
|
|
36
|
+
return undefined;
|
|
37
|
+
const color = parseColorSpec(match[3] ?? '');
|
|
38
|
+
return color === undefined ? { target } : { target, color };
|
|
39
|
+
}
|
|
40
|
+
/** Parse the color spec a terminal uses in a color reply (`#rrggbb`, `#rrrrggggbbbb`, `rgb:r/g/b`). */
|
|
41
|
+
export function parseColorSpec(spec) {
|
|
42
|
+
const value = spec.trim();
|
|
43
|
+
const hex6 = HEX6.exec(value);
|
|
44
|
+
if (hex6 !== null) {
|
|
45
|
+
const hex = hex6[1];
|
|
46
|
+
return { r: Number.parseInt(hex.slice(0, 2), 16), g: Number.parseInt(hex.slice(2, 4), 16), b: Number.parseInt(hex.slice(4, 6), 16) };
|
|
47
|
+
}
|
|
48
|
+
const hex12 = HEX12.exec(value);
|
|
49
|
+
if (hex12 !== null) {
|
|
50
|
+
const hex = hex12[1];
|
|
51
|
+
return { r: channel(hex.slice(0, 4)), g: channel(hex.slice(4, 8)), b: channel(hex.slice(8, 12)) };
|
|
52
|
+
}
|
|
53
|
+
const rgb = RGB_SPEC.exec(value);
|
|
54
|
+
if (rgb !== null)
|
|
55
|
+
return { r: channel(rgb[1]), g: channel(rgb[2]), b: channel(rgb[3]) };
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
/** Parse a CSI ?997 report; `2` means the terminal describes itself as light. */
|
|
59
|
+
export function parseSchemeReply(data) {
|
|
60
|
+
const match = /^\x1b\[\?997;([12])n$/u.exec(data);
|
|
61
|
+
if (match === null)
|
|
62
|
+
return undefined;
|
|
63
|
+
return match[1] === '2' ? 'light' : 'dark';
|
|
64
|
+
}
|
|
65
|
+
/** Fold one reply into the accumulated description, keeping earlier fields the reply does not answer. */
|
|
66
|
+
export function mergeColorReply(colors, reply) {
|
|
67
|
+
if (reply.target === 'foreground')
|
|
68
|
+
return reply.color === undefined ? colors : { ...colors, foreground: reply.color };
|
|
69
|
+
if (reply.target === 'background')
|
|
70
|
+
return reply.color === undefined ? colors : { ...colors, background: reply.color };
|
|
71
|
+
if (reply.color === undefined)
|
|
72
|
+
return colors;
|
|
73
|
+
const entries = Array.from({ length: 16 }, (_, index) => colors.entries?.[index] ?? colors.palette?.[index]);
|
|
74
|
+
entries[reply.target] = reply.color;
|
|
75
|
+
// Publishing needs every index present; the accumulator keeps the partial
|
|
76
|
+
// report until then.
|
|
77
|
+
return entries.every((entry) => entry !== undefined)
|
|
78
|
+
? { ...colors, entries, palette: entries }
|
|
79
|
+
: { ...colors, entries };
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Stable key for everything reported colors can change; two reports with the
|
|
83
|
+
* same colors produce the same key, so caches never stale-hit across a
|
|
84
|
+
* light/dark switch.
|
|
85
|
+
*/
|
|
86
|
+
export function terminalColorsKey(colors) {
|
|
87
|
+
if (colors === undefined)
|
|
88
|
+
return '';
|
|
89
|
+
// Every frame asks once per cached block; a new report is a new object.
|
|
90
|
+
const known = terminalColorsKeys.get(colors);
|
|
91
|
+
if (known !== undefined)
|
|
92
|
+
return known;
|
|
93
|
+
const rgb = (color) => color === undefined ? '' : `${color.r},${color.g},${color.b}`;
|
|
94
|
+
const key = [rgb(colors.foreground), rgb(colors.background), colors.scheme ?? '', (colors.palette ?? []).map(rgb).join(';')].join('|');
|
|
95
|
+
terminalColorsKeys.set(colors, key);
|
|
96
|
+
return key;
|
|
97
|
+
}
|
|
98
|
+
const terminalColorsKeys = new WeakMap();
|
|
99
|
+
/** Convert one 8-bit sRGB color to Oklab (Björn Ottosson's transform). */
|
|
100
|
+
export function toOklab(color) {
|
|
101
|
+
const linear = (value) => {
|
|
102
|
+
const channelValue = value / 255;
|
|
103
|
+
return channelValue <= 0.04045 ? channelValue / 12.92 : ((channelValue + 0.055) / 1.055) ** 2.4;
|
|
104
|
+
};
|
|
105
|
+
const r = linear(color.r);
|
|
106
|
+
const g = linear(color.g);
|
|
107
|
+
const b = linear(color.b);
|
|
108
|
+
const l = Math.cbrt(0.412_221_470_8 * r + 0.536_332_536_3 * g + 0.051_445_992_9 * b);
|
|
109
|
+
const m = Math.cbrt(0.211_903_498_2 * r + 0.680_699_545_1 * g + 0.107_396_956_6 * b);
|
|
110
|
+
const s = Math.cbrt(0.088_302_461_9 * r + 0.281_718_837_6 * g + 0.629_978_700_5 * b);
|
|
111
|
+
return [
|
|
112
|
+
0.210_454_255_3 * l + 0.793_617_785 * m - 0.004_072_046_8 * s,
|
|
113
|
+
1.977_998_495_1 * l - 2.428_592_205 * m + 0.450_593_709_9 * s,
|
|
114
|
+
0.025_904_037_1 * l + 0.782_771_766_2 * m - 0.808_675_766 * s,
|
|
115
|
+
];
|
|
116
|
+
}
|
|
117
|
+
/** Squared Oklab distance; ordering is all that matters for nearest-color picks. */
|
|
118
|
+
export function labDistance(left, right) {
|
|
119
|
+
const dl = left[0] - right[0];
|
|
120
|
+
const da = left[1] - right[1];
|
|
121
|
+
const db = left[2] - right[2];
|
|
122
|
+
return dl * dl + da * da + db * db;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Index of the palette entry closest to `color` in Oklab, which is what a
|
|
126
|
+
* 16-color terminal can actually show. Returns undefined for an empty palette.
|
|
127
|
+
*/
|
|
128
|
+
export function nearestPaletteIndex(color, palette) {
|
|
129
|
+
if (palette.length === 0)
|
|
130
|
+
return undefined;
|
|
131
|
+
const target = toOklab(color);
|
|
132
|
+
let best;
|
|
133
|
+
let bestDistance = Number.POSITIVE_INFINITY;
|
|
134
|
+
for (let index = 0; index < palette.length; index += 1) {
|
|
135
|
+
const entry = palette[index];
|
|
136
|
+
// A caller may hand us a partial report; a missing entry is not a color.
|
|
137
|
+
if (entry === undefined)
|
|
138
|
+
continue;
|
|
139
|
+
const distance = labDistance(target, toOklab(entry));
|
|
140
|
+
if (distance < bestDistance) {
|
|
141
|
+
bestDistance = distance;
|
|
142
|
+
best = index;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return best;
|
|
146
|
+
}
|
|
147
|
+
/** WCAG relative luminance of one color. */
|
|
148
|
+
export function relativeLuminance(color) {
|
|
149
|
+
const channelLuminance = (value) => {
|
|
150
|
+
const channelValue = value / 255;
|
|
151
|
+
return channelValue <= 0.039_28 ? channelValue / 12.92 : ((channelValue + 0.055) / 1.055) ** 2.4;
|
|
152
|
+
};
|
|
153
|
+
return 0.2126 * channelLuminance(color.r) + 0.7152 * channelLuminance(color.g) + 0.0722 * channelLuminance(color.b);
|
|
154
|
+
}
|
|
155
|
+
/** WCAG contrast ratio; 1 means identical colors. */
|
|
156
|
+
export function contrastRatio(left, right) {
|
|
157
|
+
const a = relativeLuminance(left);
|
|
158
|
+
const b = relativeLuminance(right);
|
|
159
|
+
return (Math.max(a, b) + 0.05) / (Math.min(a, b) + 0.05);
|
|
160
|
+
}
|
|
161
|
+
/** The xterm 256-color entries above the sixteen the user configures: the 6×6×6 cube and the gray ramp. */
|
|
162
|
+
const XTERM_256 = (() => {
|
|
163
|
+
const levels = [0, 95, 135, 175, 215, 255];
|
|
164
|
+
const entries = [];
|
|
165
|
+
for (let index = 16; index < 232; index += 1) {
|
|
166
|
+
const offset = index - 16;
|
|
167
|
+
entries.push({ index, lab: toOklab({ r: levels[Math.floor(offset / 36)], g: levels[Math.floor(offset / 6) % 6], b: levels[offset % 6] }) });
|
|
168
|
+
}
|
|
169
|
+
for (let index = 232; index < 256; index += 1) {
|
|
170
|
+
const value = 8 + (index - 232) * 10;
|
|
171
|
+
entries.push({ index, lab: toOklab({ r: value, g: value, b: value }) });
|
|
172
|
+
}
|
|
173
|
+
return entries;
|
|
174
|
+
})();
|
|
175
|
+
const xterm256Cache = new Map();
|
|
176
|
+
/**
|
|
177
|
+
* The xterm-256 entry closest to `color` in Oklab, from the fixed cube and
|
|
178
|
+
* gray ramp only: indices 0-15 follow the user's palette and would make the
|
|
179
|
+
* result depend on a terminal theme we cannot see.
|
|
180
|
+
*/
|
|
181
|
+
/** First xterm-256 index of the 24-step neutral ramp. */
|
|
182
|
+
const GREY_RAMP_START = 232;
|
|
183
|
+
/**
|
|
184
|
+
* Nearest xterm-256 entry, restricted to the 24-step neutral ramp.
|
|
185
|
+
*
|
|
186
|
+
* The ramp is `232..255`, and it exists because a *surface* swatch is usually a
|
|
187
|
+
* near-neutral. Left to the whole palette, three swatches that differ by a few
|
|
188
|
+
* units of warmth all land on one entry, which is why a pending, a successful,
|
|
189
|
+
* and a failed tool card used to share a single fill on a 256-color terminal.
|
|
190
|
+
* `hueSteps` keeps that from happening: see {@link surfaceXterm256}.
|
|
191
|
+
*/
|
|
192
|
+
export function nearestXterm256Grey(color) {
|
|
193
|
+
const key = `g:${color.r},${color.g},${color.b}`;
|
|
194
|
+
const known = xterm256Cache.get(key);
|
|
195
|
+
if (known !== undefined)
|
|
196
|
+
return known;
|
|
197
|
+
const target = toOklab(color);
|
|
198
|
+
let best = GREY_RAMP_START;
|
|
199
|
+
let bestDistance = Number.POSITIVE_INFINITY;
|
|
200
|
+
for (const entry of XTERM_256) {
|
|
201
|
+
if (entry.index < GREY_RAMP_START)
|
|
202
|
+
continue;
|
|
203
|
+
const distance = labDistance(target, entry.lab);
|
|
204
|
+
if (distance < bestDistance) {
|
|
205
|
+
bestDistance = distance;
|
|
206
|
+
best = entry.index;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
xterm256Cache.set(key, best);
|
|
210
|
+
return best;
|
|
211
|
+
}
|
|
212
|
+
export function nearestXterm256(color) {
|
|
213
|
+
const key = `${color.r},${color.g},${color.b}`;
|
|
214
|
+
const known = xterm256Cache.get(key);
|
|
215
|
+
if (known !== undefined)
|
|
216
|
+
return known;
|
|
217
|
+
const target = toOklab(color);
|
|
218
|
+
let best = 16;
|
|
219
|
+
let bestDistance = Number.POSITIVE_INFINITY;
|
|
220
|
+
for (const entry of XTERM_256) {
|
|
221
|
+
const distance = labDistance(target, entry.lab);
|
|
222
|
+
if (distance < bestDistance) {
|
|
223
|
+
bestDistance = distance;
|
|
224
|
+
best = entry.index;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
xterm256Cache.set(key, best);
|
|
228
|
+
return best;
|
|
229
|
+
}
|
|
230
|
+
//# sourceMappingURL=terminal-colors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"terminal-colors.js","sourceRoot":"","sources":["../../src/chrome/terminal-colors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AA4BH;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,gCAAgC;MACvD,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,UAAU,KAAK,UAAU,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;AAEhF,4EAA4E;AAC5E,MAAM,CAAC,MAAM,kBAAkB,GAAG,cAAc,CAAA;AAQhD,MAAM,eAAe,GAAG,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,CAAC,GAAG,CAAC,CAAA;QAC/C,IAAI,QAAQ,GAAG,YAAY,EAAE,CAAC;YAC5B,YAAY,GAAG,QAAQ,CAAA;YACvB,IAAI,GAAG,KAAK,CAAC,KAAK,CAAA;QACpB,CAAC;IACH,CAAC;IACD,aAAa,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;IAC5B,OAAO,IAAI,CAAA;AACb,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,KAAU;IACxC,MAAM,GAAG,GAAG,GAAG,KAAK,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,EAAE,CAAA;IAC9C,MAAM,KAAK,GAAG,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IACpC,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,KAAK,CAAA;IACrC,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,CAAA;IAC7B,IAAI,IAAI,GAAG,EAAE,CAAA;IACb,IAAI,YAAY,GAAG,MAAM,CAAC,iBAAiB,CAAA;IAC3C,KAAK,MAAM,KAAK,IAAI,SAAS,EAAE,CAAC;QAC9B,MAAM,QAAQ,GAAG,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,CAAC,CAAA;QAC/C,IAAI,QAAQ,GAAG,YAAY,EAAE,CAAC;YAC5B,YAAY,GAAG,QAAQ,CAAA;YACvB,IAAI,GAAG,KAAK,CAAC,KAAK,CAAA;QACpB,CAAC;IACH,CAAC;IACD,aAAa,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;IAC5B,OAAO,IAAI,CAAA;AACb,CAAC"}
|
|
@@ -15,7 +15,15 @@ export interface ImagePlacement {
|
|
|
15
15
|
columns: number;
|
|
16
16
|
rows: number;
|
|
17
17
|
}
|
|
18
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* Which inline-image protocol this terminal speaks, if any.
|
|
20
|
+
*
|
|
21
|
+
* Every hint here is one a terminal actually sets: the Kitty flags, the
|
|
22
|
+
* Ghostty/WezTerm/Warp markers, and the multiplexers that forward the protocol
|
|
23
|
+
* (Herdr and Rex, whose panes leak the outer terminal's variables, so they are
|
|
24
|
+
* decided first). `OMDSH_IMAGE_PROTOCOL` forces an answer when detection is
|
|
25
|
+
* wrong: `kitty`, `iterm2`, or `none`.
|
|
26
|
+
*/
|
|
19
27
|
export declare function imageProtocol(env: NodeJS.ProcessEnv): ImageProtocol | undefined;
|
|
20
28
|
/** Fit in display cells while preserving the source's pixel aspect ratio. */
|
|
21
29
|
export declare function imageSize(image: PreviewImage, columns: number, rows: number, cell?: {
|
|
@@ -1,11 +1,34 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Which inline-image protocol this terminal speaks, if any.
|
|
3
|
+
*
|
|
4
|
+
* Every hint here is one a terminal actually sets: the Kitty flags, the
|
|
5
|
+
* Ghostty/WezTerm/Warp markers, and the multiplexers that forward the protocol
|
|
6
|
+
* (Herdr and Rex, whose panes leak the outer terminal's variables, so they are
|
|
7
|
+
* decided first). `OMDSH_IMAGE_PROTOCOL` forces an answer when detection is
|
|
8
|
+
* wrong: `kitty`, `iterm2`, or `none`.
|
|
9
|
+
*/
|
|
2
10
|
export function imageProtocol(env) {
|
|
3
|
-
|
|
11
|
+
const forced = (env.OMDSH_IMAGE_PROTOCOL ?? '').trim().toLowerCase();
|
|
12
|
+
if (forced === 'none')
|
|
13
|
+
return undefined;
|
|
14
|
+
if (forced === 'kitty' || forced === 'iterm2')
|
|
15
|
+
return forced;
|
|
16
|
+
// Multiplexers that do not carry graphics through to the outer terminal.
|
|
17
|
+
if (env.TMUX || env.STY || env.ZELLIJ || /^(?:tmux|screen)/u.test(env.TERM ?? ''))
|
|
4
18
|
return undefined;
|
|
5
19
|
const program = (env.TERM_PROGRAM ?? '').toLowerCase();
|
|
6
|
-
|
|
20
|
+
const term = env.TERM ?? '';
|
|
21
|
+
if (program === 'herdr' || program === 'rex' || env.HERDR_ENV === '1')
|
|
22
|
+
return 'kitty';
|
|
23
|
+
if (env.KITTY_WINDOW_ID || term === 'xterm-kitty' || program === 'kitty')
|
|
24
|
+
return 'kitty';
|
|
25
|
+
if (program === 'ghostty' || term.includes('ghostty') || env.GHOSTTY_RESOURCES_DIR)
|
|
26
|
+
return 'kitty';
|
|
27
|
+
if (env.WEZTERM_PANE || program === 'wezterm')
|
|
28
|
+
return 'kitty';
|
|
29
|
+
if (program === 'warpterminal' || env.WARP_SESSION_ID || env.WARP_TERMINAL_SESSION_UUID)
|
|
7
30
|
return 'kitty';
|
|
8
|
-
if (program === 'iterm.app' || env.LC_TERMINAL === 'iTerm2')
|
|
31
|
+
if (program === 'iterm.app' || env.ITERM_SESSION_ID || env.LC_TERMINAL === 'iTerm2')
|
|
9
32
|
return 'iterm2';
|
|
10
33
|
return undefined;
|
|
11
34
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"terminal-images.js","sourceRoot":"","sources":["../../src/chrome/terminal-images.ts"],"names":[],"mappings":"AAoBA
|
|
1
|
+
{"version":3,"file":"terminal-images.js","sourceRoot":"","sources":["../../src/chrome/terminal-images.ts"],"names":[],"mappings":"AAoBA;;;;;;;;GAQG;AACH,MAAM,UAAU,aAAa,CAAC,GAAsB;IAClD,MAAM,MAAM,GAAG,CAAC,GAAG,CAAC,oBAAoB,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAA;IACpE,IAAI,MAAM,KAAK,MAAM;QAAE,OAAO,SAAS,CAAA;IACvC,IAAI,MAAM,KAAK,OAAO,IAAI,MAAM,KAAK,QAAQ;QAAE,OAAO,MAAM,CAAA;IAC5D,yEAAyE;IACzE,IAAI,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,IAAI,mBAAmB,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC;QAAE,OAAO,SAAS,CAA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AAE,CAAA;QACzG,GAAG,IAAI,SAAS,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAA;IACxE,CAAC;IACD,OAAO,GAAG,CAAA;AACZ,CAAC;AAED,8EAA8E;AAC9E,MAAM,UAAU,WAAW,CAAC,EAAU,IAAY,OAAO,mBAAmB,EAAE,YAAY,CAAA,CAAC,CAAC"}
|
package/lib/chrome/theme.d.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* glyphs used by terminal views.
|
|
4
4
|
* @module @agi-fans/dsh-tui
|
|
5
5
|
*/
|
|
6
|
+
import { type TerminalColors } from './terminal-colors.ts';
|
|
6
7
|
/** Rounded-box drawing characters (OMP unicode preset). */
|
|
7
8
|
export declare const BOX: {
|
|
8
9
|
readonly topLeft: "╭";
|
|
@@ -50,9 +51,17 @@ export declare const SYMBOL: {
|
|
|
50
51
|
/** Braille activity spinner (OMP unicode activity frames). */
|
|
51
52
|
export declare const SPINNER: readonly ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
|
|
52
53
|
/** Semantic colors the view addresses. */
|
|
53
|
-
export type ThemeColor = 'accent' | 'border' | 'borderAccent' | 'borderMuted' | 'success' | 'error' | 'warning' | 'muted' | 'dim' | 'text' | 'userMessageText' | 'userMessageBg' | 'toolPendingBg' | 'toolSuccessBg' | 'toolErrorBg' | 'toolTitle' | 'toolOutput' | 'toolDiffAdded' | 'toolDiffRemoved' | 'toolDiffContext' | 'mdHeading' | 'mdLink' | 'mdLinkUrl' | 'mdCode' | 'mdCodeBlock' | 'mdCodeBlockBorder' | 'mdKeyword' | 'syntaxString' | 'syntaxNumber' | 'syntaxFunction' | 'syntaxType' | 'mdQuote' | 'mdListBullet' | 'thinkingText' | 'customMessageLabel';
|
|
54
|
+
export type ThemeColor = 'accent' | 'border' | 'borderAccent' | 'borderMuted' | 'success' | 'error' | 'warning' | 'muted' | 'dim' | 'text' | 'userMessageText' | 'userMessageBg' | 'toolPendingBg' | 'toolSuccessBg' | 'toolAltBg' | 'toolErrorBg' | 'toolTitle' | 'toolOutput' | 'toolDiffAdded' | 'toolDiffRemoved' | 'toolDiffContext' | 'mdHeading' | 'mdLink' | 'mdLinkUrl' | 'mdCode' | 'mdCodeBlock' | 'mdCodeBlockBorder' | 'mdKeyword' | 'syntaxString' | 'syntaxNumber' | 'syntaxFunction' | 'syntaxType' | 'mdQuote' | 'mdQuoteBorder' | 'mdHr' | 'mdListBullet' | 'shellMode' | 'thinkingText' | 'customMessageLabel';
|
|
54
55
|
/** Built-in palettes, including a few well-known oh-my-pi coding themes. */
|
|
55
|
-
|
|
56
|
+
/**
|
|
57
|
+
* Shipped palettes: one dark, one light, and the one that follows the terminal.
|
|
58
|
+
*
|
|
59
|
+
* A theme is a contract the whole TUI is read through — every card, diff, and
|
|
60
|
+
* syntax token has to stay legible on it — so the set stays small enough to hold
|
|
61
|
+
* to that standard. `system` is not a third design: it derives its surfaces from
|
|
62
|
+
* the colours the terminal reports and then follows the same rules.
|
|
63
|
+
*/
|
|
64
|
+
export declare const THEME_NAMES: readonly ["dark", "light", "system"];
|
|
56
65
|
/** One shipped palette name. */
|
|
57
66
|
export type ThemeName = (typeof THEME_NAMES)[number];
|
|
58
67
|
/** True when `value` is a shipped palette name. */
|
|
@@ -65,8 +74,12 @@ export interface Theme {
|
|
|
65
74
|
readonly name: ThemeName;
|
|
66
75
|
/** Whether SGR is emitted. */
|
|
67
76
|
readonly colors: boolean;
|
|
68
|
-
/** Whether hex colors become 24-bit SGR
|
|
77
|
+
/** Whether hex colors become 24-bit SGR. */
|
|
69
78
|
readonly trueColor: boolean;
|
|
79
|
+
/** How swatches are encoded; meaningful only when {@link Theme.colors} is true. */
|
|
80
|
+
readonly depth: ColorDepth;
|
|
81
|
+
/** Cache fingerprint covering the palette, SGR flag, depth, and reported terminal colors. */
|
|
82
|
+
readonly key: string;
|
|
70
83
|
fg(color: ThemeColor, text: string): string;
|
|
71
84
|
bg(color: ThemeColor, text: string): string;
|
|
72
85
|
getFgAnsi(color: ThemeColor): string;
|
|
@@ -81,6 +94,12 @@ export interface Theme {
|
|
|
81
94
|
}
|
|
82
95
|
/** Paint a fixed surface, restoring its paired ink and fill after nested resets. */
|
|
83
96
|
export declare function paintSurface(theme: Theme, background: ThemeColor, foreground: ThemeColor, text: string): string;
|
|
97
|
+
/**
|
|
98
|
+
* How many colors the terminal can show, which decides how a swatch is
|
|
99
|
+
* encoded. It is independent of what the terminal reports about its palette:
|
|
100
|
+
* a report changes the target values, never the encoding.
|
|
101
|
+
*/
|
|
102
|
+
export type ColorDepth = 'ansi16' | 'ansi256' | 'truecolor';
|
|
84
103
|
/**
|
|
85
104
|
* True when the environment asks for no color at all: a non-empty `NO_COLOR`
|
|
86
105
|
* (https://no-color.org) or `FORCE_COLOR=0`. An empty `NO_COLOR` counts as
|
|
@@ -88,18 +107,22 @@ export declare function paintSurface(theme: Theme, background: ThemeColor, foreg
|
|
|
88
107
|
*/
|
|
89
108
|
export declare function colorDisabledByEnv(env?: NodeJS.ProcessEnv): boolean;
|
|
90
109
|
/**
|
|
91
|
-
* Detect
|
|
92
|
-
*
|
|
93
|
-
*
|
|
110
|
+
* Detect the color depth. `NO_COLOR` (any non-empty value) and `FORCE_COLOR=0`
|
|
111
|
+
* outrank every capability hint and leave 16 colors; `COLORTERM` and Windows
|
|
112
|
+
* Terminal prove 24-bit color. Apple Terminal advertises `xterm-256color` but
|
|
113
|
+
* misdraws 24-bit sequences on the releases still in use, so it gets the
|
|
114
|
+
* 256-color cube. Known 16-color hosts stay at 16, and every other terminal is
|
|
115
|
+
* assumed to be a modern 24-bit one.
|
|
94
116
|
*/
|
|
95
|
-
export declare function
|
|
117
|
+
export declare function detectColorDepth(env?: NodeJS.ProcessEnv): ColorDepth;
|
|
96
118
|
/**
|
|
97
119
|
* Build a theme.
|
|
98
120
|
* @param colors - emit SGR when true.
|
|
99
|
-
* @param
|
|
121
|
+
* @param depth - color depth, or a boolean for 24-bit versus 16 colors; ignored when colors is false.
|
|
100
122
|
* @param name - shipped palette (`dark` default).
|
|
123
|
+
* @param terminal - what the terminal reported about itself, when a probe answered.
|
|
101
124
|
*/
|
|
102
|
-
export declare function createTheme(colors: boolean,
|
|
125
|
+
export declare function createTheme(colors: boolean, depth?: ColorDepth | boolean, name?: ThemeName, terminal?: TerminalColors): Theme;
|
|
103
126
|
/** DeepSeek mark adapted from the official SVG for a 20×6 terminal cell. */
|
|
104
127
|
export declare const DEEPSEEK_LOGO: readonly [" ⢀⣀ ⢀⡀ ", "⢀⣤⣶⣿⣿⣿⣿⣿⣿⣿⣧⣄⡀⢻⣿⣷⣶⣶⣶⡿", "⣿⡟⠛⠛⠛⠿⢿⣿⣿⣿⣿⡿⢿⣷⣾⣿⣿⠉⠉ ", "⢻⣿⣄⡀ ⢀⠈⠛⢿⣿⣿⣶⣿⣿⡿⠃ ", " ⠙⠻⢿⣶⣦⣼⣿⣷⣦⣭⣿⠿⣿⣷⠦ ", " ⠉⠉⠉⠉⠉⠁ "];
|
|
105
128
|
/**
|