@causyne/agent 1.20.111 → 1.20.116
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/docs/ARCHITECTURE.md +29 -0
- package/package.json +1 -1
- package/src/agentLoop.js +72 -37
- package/src/agentLoop.ts +70 -38
- package/src/browser/browserRuntime.js +13 -8
- package/src/browser/browserRuntime.ts +16 -8
- package/src/browser/causyneBrowser.js +7 -2
- package/src/browser/causyneBrowser.ts +8 -2
- package/src/browser/searchProviders.js +18 -7
- package/src/browser/searchProviders.ts +17 -5
- package/src/browser/snapshotWindow.js +1 -1
- package/src/browser/snapshotWindow.ts +1 -1
- package/src/browser/urlPolicy.js +21 -10
- package/src/browser/urlPolicy.ts +19 -10
- package/src/browser/workspacePreview.js +13 -1
- package/src/browser/workspacePreview.ts +11 -1
- package/src/computerUse/visionGrounding.js +31 -27
- package/src/computerUse/visionGrounding.ts +27 -27
- package/src/continuum/ui/continuumPicker.js +14 -6
- package/src/continuum/ui/continuumPicker.ts +13 -6
- package/src/continuum/ui/continuumPickerView.js +24 -15
- package/src/continuum/ui/continuumPickerView.ts +24 -16
- package/src/observer/advisory.js +32 -22
- package/src/observer/advisory.ts +30 -18
- package/src/observer/coldObserver.js +21 -33
- package/src/observer/coldObserver.ts +20 -33
- package/src/observer/evidence.js +20 -13
- package/src/observer/evidence.ts +21 -13
- package/src/observer.js +47 -12
- package/src/observer.ts +50 -18
- package/src/pluginsFactory/discovery.js +28 -16
- package/src/pluginsFactory/discovery.ts +29 -16
- package/src/pluginsFactory/pluginsFactory.js +213 -38
- package/src/pluginsFactory/pluginsFactory.ts +218 -39
- package/src/pluginsFactory/strategy.js +26 -16
- package/src/pluginsFactory/strategy.ts +34 -19
- package/src/pluginsFactory/templates.js +183 -62
- package/src/pluginsFactory/templates.ts +174 -54
- package/src/timeMachine.js +43 -22
- package/src/timeMachine.ts +44 -22
- package/src/tool-scripts/desktop_act.applescript +1 -0
- package/src/tools/computerUse.js +23 -10
- package/src/tools/computerUse.ts +19 -8
- package/src/tools/desktopAct.js +12 -1
- package/src/tools/pluginsFactory.js +108 -5
- package/src/tools/pluginsFactory.ts +115 -5
- package/src/tui/CausyneRotor.js +24 -10
- package/src/tui/CausyneRotor.ts +25 -10
- package/src/tui/activityLayout.js +9 -5
- package/src/tui/activityLayout.ts +9 -5
- package/src/tui/ask.js +34 -14
- package/src/tui/banner.js +55 -18
- package/src/tui/banner.ts +52 -17
- package/src/tui/block.js +47 -20
- package/src/tui/block.ts +54 -27
- package/src/tui/chatRenderer.js +135 -83
- package/src/tui/chatboxClipboard.js +12 -5
- package/src/tui/chatboxClipboard.ts +10 -4
- package/src/tui/clipboardImage.js +52 -42
- package/src/tui/clipboardImage.ts +50 -39
- package/src/tui/clipboardSync.js +12 -1
- package/src/tui/clipboardSync.ts +9 -1
- package/src/tui/codeProgress.js +57 -26
- package/src/tui/codeProgress.ts +57 -25
- package/src/tui/codeStreamRenderer.js +59 -14
- package/src/tui/codeStreamRenderer.ts +58 -14
- package/src/tui/commandPresentation.js +9 -2
- package/src/tui/commandPresentation.ts +9 -2
- package/src/tui/completion.js +45 -23
- package/src/tui/composerControls.js +21 -10
- package/src/tui/composerControls.ts +18 -10
- package/src/tui/composerGeometry.js +6 -4
- package/src/tui/composerGeometry.ts +6 -4
- package/src/tui/consoleGuard.js +29 -7
- package/src/tui/consoleGuard.ts +28 -7
- package/src/tui/dialogs.js +134 -71
- package/src/tui/diff.js +8 -4
- package/src/tui/history.js +6 -5
- package/src/tui/home.js +25 -13
- package/src/tui/homeView.js +37 -18
- package/src/tui/homeView.ts +38 -18
- package/src/tui/inlineSlash.js +6 -5
- package/src/tui/inlineSlash.ts +6 -5
- package/src/tui/keys.js +33 -17
- package/src/tui/layout.js +27 -9
- package/src/tui/layout.ts +26 -9
- package/src/tui/lineEditor.js +49 -23
- package/src/tui/markdownMath.js +64 -14
- package/src/tui/markdownMath.ts +69 -13
- package/src/tui/messageActionPlacement.js +28 -13
- package/src/tui/messageActionPlacement.ts +28 -13
- package/src/tui/messageInteraction.js +111 -46
- package/src/tui/messageInteraction.ts +115 -47
- package/src/tui/modelPicker.js +44 -15
- package/src/tui/modelPicker.ts +48 -15
- package/src/tui/observerPicker.js +56 -13
- package/src/tui/observerPicker.ts +73 -30
- package/src/tui/overlay.js +79 -35
- package/src/tui/overlay.ts +81 -34
- package/src/tui/prompt.js +162 -94
- package/src/tui/runningLight.js +1 -1
- package/src/tui/runningLight.ts +1 -1
- package/src/tui/scrollInteraction.js +64 -36
- package/src/tui/scrollInteraction.ts +70 -37
- package/src/tui/selectList.js +60 -32
- package/src/tui/sessionLayout.js +11 -3
- package/src/tui/sessionLayout.ts +10 -3
- package/src/tui/sessionPicker.js +74 -46
- package/src/tui/sessionPicker.ts +73 -48
- package/src/tui/sessionPickerView.js +32 -19
- package/src/tui/sessionPickerView.ts +31 -18
- package/src/tui/sessionSidebar.js +87 -57
- package/src/tui/sessionSidebar.ts +90 -54
- package/src/tui/setup.js +28 -3
- package/src/tui/setup.ts +27 -3
- package/src/tui/skillAuthoring.js +11 -5
- package/src/tui/skillAuthoring.ts +11 -5
- package/src/tui/smartLinkClick.js +75 -23
- package/src/tui/smartLinkClick.ts +86 -26
- package/src/tui/stage.js +47 -16
- package/src/tui/stage.ts +53 -18
- package/src/tui/stageSurface.js +120 -49
- package/src/tui/statusLine.js +85 -53
- package/src/tui/statusLine.ts +82 -46
- package/src/tui/terminalInputFramer.js +5 -2
- package/src/tui/text.js +117 -46
- package/src/tui/text.ts +113 -43
- package/src/tui/textLayout.js +6 -4
- package/src/tui/textLayout.ts +11 -5
- package/src/tui/theme.js +17 -8
- package/src/tui/thinkingBox.js +95 -95
- package/src/tui/thinkingBox.ts +105 -80
- package/src/tui/toolActivityPolicy.js +8 -1
- package/src/tui/toolActivityPolicy.ts +7 -1
- package/src/tui/toolDisplay.js +15 -6
- package/src/tui/toolDisplay.ts +16 -6
- package/src/tui/toolOutputNormalizer.js +16 -3
- package/src/tui/toolOutputNormalizer.ts +13 -3
- package/src/tui/transcript.js +15 -9
- package/src/tui/turnRail.js +156 -67
- package/src/tui/turnRail.ts +155 -58
- package/src/tui/usageCard.js +80 -45
- package/src/tui/usageCard.ts +81 -46
- package/src/tui/viewport.js +48 -23
- package/src/tui/viewport.ts +48 -27
- package/src/tui/viewportAnchor.js +2 -2
- package/src/tui/viewportAnchor.ts +2 -2
- package/src/tui/workspaceFileIndex.js +8 -6
- package/src/tui/workspaceFileIndex.ts +8 -6
- package/src/tui/workspaceSwitch.js +13 -10
- package/src/tui/workspaceSwitch.ts +11 -7
package/src/tui/overlay.js
CHANGED
|
@@ -15,7 +15,10 @@
|
|
|
15
15
|
// Pure Node over ./screen.js, ./theme.js and ./text.js. No dependency, no shell.
|
|
16
16
|
// @ts-expect-error theme.js has no TypeScript declaration yet.
|
|
17
17
|
import { paint, bold, dim, fill, GLYPHS, HAS_COLOR, HAS_UNICODE } from './theme.js';
|
|
18
|
-
import { truncate, visibleWidth } from './text.js';
|
|
18
|
+
import { safeDisplay, truncate, visibleWidth } from './text.js';
|
|
19
|
+
function cleanSingleLine(value) {
|
|
20
|
+
return safeDisplay(typeof value === 'string' ? value : String(value ?? '')).replace(/[\r\n]+/g, ' ');
|
|
21
|
+
}
|
|
19
22
|
// Box-drawing set, degrading with the rest of the glyphs.
|
|
20
23
|
export const FRAME = HAS_UNICODE
|
|
21
24
|
? { tl: '╭', tr: '╮', bl: '╰', br: '╯', h: '─', v: '│' }
|
|
@@ -58,35 +61,47 @@ export function dimBackdrop(screen, viewport, hole) {
|
|
|
58
61
|
* the transcript bleeding through the gaps between its rows.
|
|
59
62
|
*/
|
|
60
63
|
export function drawPanel(screen, rect, { title = '', footer = '' } = {}) {
|
|
61
|
-
if (rect.
|
|
62
|
-
return { x:
|
|
63
|
-
|
|
64
|
-
const
|
|
64
|
+
if (!screen || !rect || typeof screen.fill !== 'function' || typeof screen.put !== 'function') {
|
|
65
|
+
return { x: 0, y: 0, width: 0, height: 0 };
|
|
66
|
+
}
|
|
67
|
+
const x = Number.isFinite(rect.x) ? Math.floor(rect.x) : 0;
|
|
68
|
+
const y = Number.isFinite(rect.y) ? Math.floor(rect.y) : 0;
|
|
69
|
+
if (!Number.isFinite(rect.x) || !Number.isFinite(rect.y) || !Number.isFinite(rect.width) || !Number.isFinite(rect.height)) {
|
|
70
|
+
return { x, y, width: 0, height: 0 };
|
|
71
|
+
}
|
|
72
|
+
const w = Math.floor(rect.width);
|
|
73
|
+
const h = Math.floor(rect.height);
|
|
74
|
+
if (w < 4 || h < 3)
|
|
75
|
+
return { x, y, width: 0, height: 0 };
|
|
76
|
+
screen.fill(x, y, w, h, '');
|
|
77
|
+
const inner = w - 2;
|
|
65
78
|
const line = FRAME.h.repeat(inner);
|
|
66
79
|
// Title sits in the top border, the way every terminal dialog has since curses.
|
|
67
80
|
let top = FRAME.tl + line + FRAME.tr;
|
|
68
|
-
|
|
69
|
-
|
|
81
|
+
const cleanTitle = cleanSingleLine(title).trim();
|
|
82
|
+
if (cleanTitle && inner > 4) {
|
|
83
|
+
const label = ` ${truncate(cleanTitle, inner - 4, GLYPHS.ellipsis)} `;
|
|
70
84
|
const width = visibleWidth(label);
|
|
71
85
|
top = FRAME.tl + FRAME.h + label + FRAME.h.repeat(Math.max(0, inner - width - 1)) + FRAME.tr;
|
|
72
86
|
}
|
|
73
87
|
let bottom = FRAME.bl + line + FRAME.br;
|
|
74
|
-
|
|
75
|
-
|
|
88
|
+
const cleanFooter = cleanSingleLine(footer).trim();
|
|
89
|
+
if (cleanFooter && inner > 4) {
|
|
90
|
+
const label = ` ${truncate(cleanFooter, inner - 4, GLYPHS.ellipsis)} `;
|
|
76
91
|
const width = visibleWidth(label);
|
|
77
92
|
bottom = FRAME.bl + FRAME.h.repeat(Math.max(0, inner - width - 1)) + label + FRAME.h + FRAME.br;
|
|
78
93
|
}
|
|
79
|
-
screen.put(
|
|
80
|
-
screen.put(
|
|
81
|
-
for (let row =
|
|
82
|
-
screen.put(
|
|
83
|
-
screen.put(
|
|
94
|
+
screen.put(x, y, paint('rule', top), w);
|
|
95
|
+
screen.put(x, y + h - 1, paint('rule', bottom), w);
|
|
96
|
+
for (let row = y + 1; row < y + h - 1; row++) {
|
|
97
|
+
screen.put(x, row, paint('rule', FRAME.v), 1);
|
|
98
|
+
screen.put(x + w - 1, row, paint('rule', FRAME.v), 1);
|
|
84
99
|
}
|
|
85
100
|
return {
|
|
86
|
-
x:
|
|
87
|
-
y:
|
|
88
|
-
width: Math.max(0,
|
|
89
|
-
height: Math.max(0,
|
|
101
|
+
x: x + 2,
|
|
102
|
+
y: y + 1,
|
|
103
|
+
width: Math.max(0, w - 4),
|
|
104
|
+
height: Math.max(0, h - 2)
|
|
90
105
|
};
|
|
91
106
|
}
|
|
92
107
|
/**
|
|
@@ -127,13 +142,24 @@ export class Layer {
|
|
|
127
142
|
preferredHeight() { return this.height; }
|
|
128
143
|
/** Panel rect, centred and clamped to the viewport. */
|
|
129
144
|
rect(viewport) {
|
|
130
|
-
const
|
|
131
|
-
const
|
|
132
|
-
const
|
|
145
|
+
const vp = viewport && typeof viewport === 'object' ? viewport : { x: 0, y: 0, width: 80, height: 24 };
|
|
146
|
+
const vx = Number.isFinite(vp.x) ? Math.floor(vp.x) : 0;
|
|
147
|
+
const vy = Number.isFinite(vp.y) ? Math.floor(vp.y) : 0;
|
|
148
|
+
const vw = Number.isFinite(vp.width) ? Math.max(4, Math.floor(vp.width)) : 80;
|
|
149
|
+
const vh = Number.isFinite(vp.height) ? Math.max(3, Math.floor(vp.height)) : 24;
|
|
150
|
+
const layerWidth = Number.isFinite(this.width) ? Math.max(4, Math.floor(this.width)) : 64;
|
|
151
|
+
const layerHeight = Number.isFinite(this.height) ? Math.max(3, Math.floor(this.height)) : 16;
|
|
152
|
+
const rawPreferred = this.preferredHeight();
|
|
153
|
+
const safePreferred = Number.isFinite(rawPreferred) ? Math.floor(rawPreferred) : layerHeight;
|
|
154
|
+
const maxW = vw - 4 >= 20 ? vw - 4 : vw;
|
|
155
|
+
const width = Math.min(layerWidth, Math.max(4, maxW));
|
|
156
|
+
const maxH = vh - 4 >= 5 ? vh - 4 : vh;
|
|
157
|
+
const wanted = Math.max(3, Math.min(safePreferred, layerHeight));
|
|
158
|
+
const height = Math.min(wanted, Math.max(3, maxH));
|
|
133
159
|
return {
|
|
134
|
-
x:
|
|
160
|
+
x: vx + Math.floor((vw - width) / 2),
|
|
135
161
|
// A quarter down reads as centred; dead centre sits visually too low.
|
|
136
|
-
y:
|
|
162
|
+
y: vy + Math.max(1, Math.floor((vh - height) / 4)),
|
|
137
163
|
width,
|
|
138
164
|
height
|
|
139
165
|
};
|
|
@@ -196,8 +222,15 @@ export class OverlayStack {
|
|
|
196
222
|
screen.put(inner.x, inner.y + row, rows[row] ?? '', inner.width);
|
|
197
223
|
}
|
|
198
224
|
// Only the topmost layer may own the caret.
|
|
199
|
-
if (index === this.layers.length - 1 &&
|
|
200
|
-
|
|
225
|
+
if (index === this.layers.length - 1 &&
|
|
226
|
+
layer.cursor &&
|
|
227
|
+
inner.width > 0 &&
|
|
228
|
+
inner.height > 0 &&
|
|
229
|
+
Number.isFinite(layer.cursor.x) &&
|
|
230
|
+
Number.isFinite(layer.cursor.y)) {
|
|
231
|
+
const cursorX = Math.max(0, Math.min(inner.width - 1, Math.floor(layer.cursor.x)));
|
|
232
|
+
const cursorY = Math.max(0, Math.min(inner.height - 1, Math.floor(layer.cursor.y)));
|
|
233
|
+
screen.setCursor(inner.x + cursorX, inner.y + cursorY);
|
|
201
234
|
}
|
|
202
235
|
}
|
|
203
236
|
}
|
|
@@ -216,29 +249,40 @@ export class OverlayStack {
|
|
|
216
249
|
* opaque surface background and legible header/footer typography.
|
|
217
250
|
*/
|
|
218
251
|
export function panelRows(layer, width, maxHeight) {
|
|
219
|
-
const
|
|
252
|
+
const safeLayer = layer && typeof layer === 'object' ? layer : {};
|
|
253
|
+
const safeWidth = Number.isFinite(width) ? Math.floor(width) : 8;
|
|
254
|
+
const rawPreferred = typeof safeLayer.preferredHeight === 'function' ? safeLayer.preferredHeight() : 3;
|
|
255
|
+
const preferred = Number.isFinite(rawPreferred) ? Math.floor(rawPreferred) : 3;
|
|
256
|
+
const safeMaxHeight = Number.isFinite(maxHeight)
|
|
257
|
+
? Math.floor(maxHeight)
|
|
258
|
+
: (maxHeight === Infinity ? preferred : 3);
|
|
259
|
+
const frameWidth = Math.max(8, safeWidth);
|
|
220
260
|
const inner = frameWidth - 4; // two borders, one pad each side
|
|
221
|
-
const bodyHeight = Math.max(1, Math.min(
|
|
222
|
-
const
|
|
223
|
-
const
|
|
224
|
-
const
|
|
261
|
+
const bodyHeight = Math.max(1, Math.min(preferred, safeMaxHeight) - 2);
|
|
262
|
+
const rawBody = typeof safeLayer.body === 'function' ? safeLayer.body(inner, bodyHeight) : [];
|
|
263
|
+
const body = Array.isArray(rawBody) ? rawBody : [];
|
|
264
|
+
const borderRole = safeLayer.borderRole || 'rule';
|
|
265
|
+
const surfaceRole = safeLayer.surfaceRole || 'surface';
|
|
225
266
|
const line = FRAME.h.repeat(frameWidth - 2);
|
|
226
267
|
let top = paint(borderRole, FRAME.tl + line + FRAME.tr);
|
|
227
|
-
|
|
228
|
-
|
|
268
|
+
const cleanTitle = cleanSingleLine(safeLayer.title || '').trim();
|
|
269
|
+
if (cleanTitle) {
|
|
270
|
+
const label = ` ${truncate(cleanTitle, Math.max(0, inner - 4), GLYPHS.ellipsis)} `;
|
|
229
271
|
const trail = FRAME.h.repeat(Math.max(0, frameWidth - 3 - visibleWidth(label)));
|
|
230
272
|
top = paint(borderRole, FRAME.tl + FRAME.h) + bold(paint('ink', label)) + paint(borderRole, trail + FRAME.tr);
|
|
231
273
|
}
|
|
232
274
|
let bottom = paint(borderRole, FRAME.bl + line + FRAME.br);
|
|
233
|
-
|
|
234
|
-
|
|
275
|
+
const cleanFooter = cleanSingleLine(safeLayer.footer || '').trim();
|
|
276
|
+
if (cleanFooter) {
|
|
277
|
+
const label = ` ${truncate(cleanFooter, Math.max(0, inner - 4), GLYPHS.ellipsis)} `;
|
|
235
278
|
const lead = FRAME.h.repeat(Math.max(0, frameWidth - 3 - visibleWidth(label)));
|
|
236
279
|
bottom = paint(borderRole, FRAME.bl + lead) + dim(label) + paint(borderRole, FRAME.h + FRAME.br);
|
|
237
280
|
}
|
|
238
281
|
const edge = paint(borderRole, FRAME.v);
|
|
239
282
|
const rows = [fill(surfaceRole, top)];
|
|
240
283
|
for (let index = 0; index < bodyHeight; index++) {
|
|
241
|
-
const
|
|
284
|
+
const cleanRow = body[index] == null ? '' : cleanSingleLine(body[index]);
|
|
285
|
+
const content = truncate(cleanRow, inner, GLYPHS.ellipsis);
|
|
242
286
|
const pad = ' '.repeat(Math.max(0, inner - visibleWidth(content)));
|
|
243
287
|
rows.push(fill(surfaceRole, `${edge} ${content}${pad} ${edge}`));
|
|
244
288
|
}
|
package/src/tui/overlay.ts
CHANGED
|
@@ -16,7 +16,11 @@
|
|
|
16
16
|
|
|
17
17
|
// @ts-expect-error theme.js has no TypeScript declaration yet.
|
|
18
18
|
import { paint, bold, dim, fill, GLYPHS, HAS_COLOR, HAS_UNICODE } from './theme.js';
|
|
19
|
-
import { truncate, visibleWidth } from './text.js';
|
|
19
|
+
import { safeDisplay, truncate, visibleWidth } from './text.js';
|
|
20
|
+
|
|
21
|
+
function cleanSingleLine(value: unknown): string {
|
|
22
|
+
return safeDisplay(typeof value === 'string' ? value : String(value ?? '')).replace(/[\r\n]+/g, ' ');
|
|
23
|
+
}
|
|
20
24
|
|
|
21
25
|
export interface OverlayRect {
|
|
22
26
|
x: number;
|
|
@@ -99,41 +103,53 @@ export function drawPanel(
|
|
|
99
103
|
rect: OverlayRect,
|
|
100
104
|
{ title = '', footer = '' }: { title?: string; footer?: string } = {}
|
|
101
105
|
): OverlayRect {
|
|
102
|
-
if (
|
|
106
|
+
if (!screen || !rect || typeof screen.fill !== 'function' || typeof screen.put !== 'function') {
|
|
107
|
+
return { x: 0, y: 0, width: 0, height: 0 };
|
|
108
|
+
}
|
|
109
|
+
const x = Number.isFinite(rect.x) ? Math.floor(rect.x) : 0;
|
|
110
|
+
const y = Number.isFinite(rect.y) ? Math.floor(rect.y) : 0;
|
|
111
|
+
if (!Number.isFinite(rect.x) || !Number.isFinite(rect.y) || !Number.isFinite(rect.width) || !Number.isFinite(rect.height)) {
|
|
112
|
+
return { x, y, width: 0, height: 0 };
|
|
113
|
+
}
|
|
114
|
+
const w = Math.floor(rect.width);
|
|
115
|
+
const h = Math.floor(rect.height);
|
|
116
|
+
if (w < 4 || h < 3) return { x, y, width: 0, height: 0 };
|
|
103
117
|
|
|
104
|
-
screen.fill(
|
|
118
|
+
screen.fill(x, y, w, h, '');
|
|
105
119
|
|
|
106
|
-
const inner =
|
|
120
|
+
const inner = w - 2;
|
|
107
121
|
const line = FRAME.h.repeat(inner);
|
|
108
122
|
|
|
109
123
|
// Title sits in the top border, the way every terminal dialog has since curses.
|
|
110
124
|
let top = FRAME.tl + line + FRAME.tr;
|
|
111
|
-
|
|
112
|
-
|
|
125
|
+
const cleanTitle = cleanSingleLine(title).trim();
|
|
126
|
+
if (cleanTitle && inner > 4) {
|
|
127
|
+
const label = ` ${truncate(cleanTitle, inner - 4, GLYPHS.ellipsis)} `;
|
|
113
128
|
const width = visibleWidth(label);
|
|
114
129
|
top = FRAME.tl + FRAME.h + label + FRAME.h.repeat(Math.max(0, inner - width - 1)) + FRAME.tr;
|
|
115
130
|
}
|
|
116
131
|
|
|
117
132
|
let bottom = FRAME.bl + line + FRAME.br;
|
|
118
|
-
|
|
119
|
-
|
|
133
|
+
const cleanFooter = cleanSingleLine(footer).trim();
|
|
134
|
+
if (cleanFooter && inner > 4) {
|
|
135
|
+
const label = ` ${truncate(cleanFooter, inner - 4, GLYPHS.ellipsis)} `;
|
|
120
136
|
const width = visibleWidth(label);
|
|
121
137
|
bottom = FRAME.bl + FRAME.h.repeat(Math.max(0, inner - width - 1)) + label + FRAME.h + FRAME.br;
|
|
122
138
|
}
|
|
123
139
|
|
|
124
|
-
screen.put(
|
|
125
|
-
screen.put(
|
|
140
|
+
screen.put(x, y, paint('rule', top), w);
|
|
141
|
+
screen.put(x, y + h - 1, paint('rule', bottom), w);
|
|
126
142
|
|
|
127
|
-
for (let row =
|
|
128
|
-
screen.put(
|
|
129
|
-
screen.put(
|
|
143
|
+
for (let row = y + 1; row < y + h - 1; row++) {
|
|
144
|
+
screen.put(x, row, paint('rule', FRAME.v), 1);
|
|
145
|
+
screen.put(x + w - 1, row, paint('rule', FRAME.v), 1);
|
|
130
146
|
}
|
|
131
147
|
|
|
132
148
|
return {
|
|
133
|
-
x:
|
|
134
|
-
y:
|
|
135
|
-
width: Math.max(0,
|
|
136
|
-
height: Math.max(0,
|
|
149
|
+
x: x + 2,
|
|
150
|
+
y: y + 1,
|
|
151
|
+
width: Math.max(0, w - 4),
|
|
152
|
+
height: Math.max(0, h - 2)
|
|
137
153
|
};
|
|
138
154
|
}
|
|
139
155
|
|
|
@@ -178,13 +194,24 @@ export class Layer {
|
|
|
178
194
|
|
|
179
195
|
/** Panel rect, centred and clamped to the viewport. */
|
|
180
196
|
rect(viewport: OverlayRect): OverlayRect {
|
|
181
|
-
const
|
|
182
|
-
const
|
|
183
|
-
const
|
|
197
|
+
const vp = viewport && typeof viewport === 'object' ? viewport : { x: 0, y: 0, width: 80, height: 24 };
|
|
198
|
+
const vx = Number.isFinite(vp.x) ? Math.floor(vp.x) : 0;
|
|
199
|
+
const vy = Number.isFinite(vp.y) ? Math.floor(vp.y) : 0;
|
|
200
|
+
const vw = Number.isFinite(vp.width) ? Math.max(4, Math.floor(vp.width)) : 80;
|
|
201
|
+
const vh = Number.isFinite(vp.height) ? Math.max(3, Math.floor(vp.height)) : 24;
|
|
202
|
+
const layerWidth = Number.isFinite(this.width) ? Math.max(4, Math.floor(this.width)) : 64;
|
|
203
|
+
const layerHeight = Number.isFinite(this.height) ? Math.max(3, Math.floor(this.height)) : 16;
|
|
204
|
+
const rawPreferred = this.preferredHeight();
|
|
205
|
+
const safePreferred = Number.isFinite(rawPreferred) ? Math.floor(rawPreferred) : layerHeight;
|
|
206
|
+
const maxW = vw - 4 >= 20 ? vw - 4 : vw;
|
|
207
|
+
const width = Math.min(layerWidth, Math.max(4, maxW));
|
|
208
|
+
const maxH = vh - 4 >= 5 ? vh - 4 : vh;
|
|
209
|
+
const wanted = Math.max(3, Math.min(safePreferred, layerHeight));
|
|
210
|
+
const height = Math.min(wanted, Math.max(3, maxH));
|
|
184
211
|
return {
|
|
185
|
-
x:
|
|
212
|
+
x: vx + Math.floor((vw - width) / 2),
|
|
186
213
|
// A quarter down reads as centred; dead centre sits visually too low.
|
|
187
|
-
y:
|
|
214
|
+
y: vy + Math.max(1, Math.floor((vh - height) / 4)),
|
|
188
215
|
width,
|
|
189
216
|
height
|
|
190
217
|
};
|
|
@@ -254,8 +281,17 @@ export class OverlayStack {
|
|
|
254
281
|
}
|
|
255
282
|
|
|
256
283
|
// Only the topmost layer may own the caret.
|
|
257
|
-
if (
|
|
258
|
-
|
|
284
|
+
if (
|
|
285
|
+
index === this.layers.length - 1 &&
|
|
286
|
+
layer.cursor &&
|
|
287
|
+
inner.width > 0 &&
|
|
288
|
+
inner.height > 0 &&
|
|
289
|
+
Number.isFinite(layer.cursor.x) &&
|
|
290
|
+
Number.isFinite(layer.cursor.y)
|
|
291
|
+
) {
|
|
292
|
+
const cursorX = Math.max(0, Math.min(inner.width - 1, Math.floor(layer.cursor.x)));
|
|
293
|
+
const cursorY = Math.max(0, Math.min(inner.height - 1, Math.floor(layer.cursor.y)));
|
|
294
|
+
screen.setCursor(inner.x + cursorX, inner.y + cursorY);
|
|
259
295
|
}
|
|
260
296
|
}
|
|
261
297
|
}
|
|
@@ -275,25 +311,35 @@ export class OverlayStack {
|
|
|
275
311
|
* opaque surface background and legible header/footer typography.
|
|
276
312
|
*/
|
|
277
313
|
export function panelRows(layer: PanelRenderableLayer, width: number, maxHeight: number): string[] {
|
|
278
|
-
const
|
|
314
|
+
const safeLayer: Partial<PanelRenderableLayer> = layer && typeof layer === 'object' ? layer : {};
|
|
315
|
+
const safeWidth = Number.isFinite(width) ? Math.floor(width) : 8;
|
|
316
|
+
const rawPreferred = typeof safeLayer.preferredHeight === 'function' ? safeLayer.preferredHeight() : 3;
|
|
317
|
+
const preferred = Number.isFinite(rawPreferred) ? Math.floor(rawPreferred) : 3;
|
|
318
|
+
const safeMaxHeight = Number.isFinite(maxHeight)
|
|
319
|
+
? Math.floor(maxHeight)
|
|
320
|
+
: (maxHeight === Infinity ? preferred : 3);
|
|
321
|
+
const frameWidth = Math.max(8, safeWidth);
|
|
279
322
|
const inner = frameWidth - 4; // two borders, one pad each side
|
|
280
|
-
const bodyHeight = Math.max(1, Math.min(
|
|
281
|
-
const
|
|
323
|
+
const bodyHeight = Math.max(1, Math.min(preferred, safeMaxHeight) - 2);
|
|
324
|
+
const rawBody = typeof safeLayer.body === 'function' ? safeLayer.body(inner, bodyHeight) : [];
|
|
325
|
+
const body = Array.isArray(rawBody) ? rawBody : [];
|
|
282
326
|
|
|
283
|
-
const borderRole =
|
|
284
|
-
const surfaceRole =
|
|
327
|
+
const borderRole = safeLayer.borderRole || 'rule';
|
|
328
|
+
const surfaceRole = safeLayer.surfaceRole || 'surface';
|
|
285
329
|
const line = FRAME.h.repeat(frameWidth - 2);
|
|
286
330
|
|
|
287
331
|
let top = paint(borderRole, FRAME.tl + line + FRAME.tr);
|
|
288
|
-
|
|
289
|
-
|
|
332
|
+
const cleanTitle = cleanSingleLine(safeLayer.title || '').trim();
|
|
333
|
+
if (cleanTitle) {
|
|
334
|
+
const label = ` ${truncate(cleanTitle, Math.max(0, inner - 4), GLYPHS.ellipsis)} `;
|
|
290
335
|
const trail = FRAME.h.repeat(Math.max(0, frameWidth - 3 - visibleWidth(label)));
|
|
291
336
|
top = paint(borderRole, FRAME.tl + FRAME.h) + bold(paint('ink', label)) + paint(borderRole, trail + FRAME.tr);
|
|
292
337
|
}
|
|
293
338
|
|
|
294
339
|
let bottom = paint(borderRole, FRAME.bl + line + FRAME.br);
|
|
295
|
-
|
|
296
|
-
|
|
340
|
+
const cleanFooter = cleanSingleLine(safeLayer.footer || '').trim();
|
|
341
|
+
if (cleanFooter) {
|
|
342
|
+
const label = ` ${truncate(cleanFooter, Math.max(0, inner - 4), GLYPHS.ellipsis)} `;
|
|
297
343
|
const lead = FRAME.h.repeat(Math.max(0, frameWidth - 3 - visibleWidth(label)));
|
|
298
344
|
bottom = paint(borderRole, FRAME.bl + lead) + dim(label) + paint(borderRole, FRAME.h + FRAME.br);
|
|
299
345
|
}
|
|
@@ -301,7 +347,8 @@ export function panelRows(layer: PanelRenderableLayer, width: number, maxHeight:
|
|
|
301
347
|
const edge = paint(borderRole, FRAME.v);
|
|
302
348
|
const rows: string[] = [fill(surfaceRole, top)];
|
|
303
349
|
for (let index = 0; index < bodyHeight; index++) {
|
|
304
|
-
const
|
|
350
|
+
const cleanRow = body[index] == null ? '' : cleanSingleLine(body[index]);
|
|
351
|
+
const content = truncate(cleanRow, inner, GLYPHS.ellipsis);
|
|
305
352
|
const pad = ' '.repeat(Math.max(0, inner - visibleWidth(content)));
|
|
306
353
|
rows.push(fill(surfaceRole, `${edge} ${content}${pad} ${edge}`));
|
|
307
354
|
}
|