@juicesharp/rpiv-ask-user-question 2.13.0 → 2.13.2
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/package.json +3 -2
- package/state/build-questionnaire.ts +1 -0
- package/view/components/preview/preview-block-renderer.ts +39 -18
- package/view/components/preview/preview-pane.ts +121 -41
- package/view/dialog-builder.ts +50 -50
- package/view/scroll-window.ts +73 -0
- package/view/tab-content-strategy.ts +3 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@juicesharp/rpiv-ask-user-question",
|
|
3
|
-
"version": "2.13.
|
|
3
|
+
"version": "2.13.2",
|
|
4
4
|
"description": "Pi extension. A structured questionnaire the model can put to you when it would otherwise guess, with typed options instead of free-form replies.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
|
@@ -75,6 +75,7 @@
|
|
|
75
75
|
"view/components/wrapping-select.ts",
|
|
76
76
|
"view/dialog-builder.ts",
|
|
77
77
|
"view/props-adapter.ts",
|
|
78
|
+
"view/scroll-window.ts",
|
|
78
79
|
"view/stateful-view.ts",
|
|
79
80
|
"view/tab-components.ts",
|
|
80
81
|
"view/tab-content-strategy.ts"
|
|
@@ -97,6 +98,6 @@
|
|
|
97
98
|
}
|
|
98
99
|
},
|
|
99
100
|
"dependencies": {
|
|
100
|
-
"@juicesharp/rpiv-config": "^2.13.
|
|
101
|
+
"@juicesharp/rpiv-config": "^2.13.2"
|
|
101
102
|
}
|
|
102
103
|
}
|
|
@@ -29,6 +29,26 @@ function contentBudgetFor(mode: PreviewLayoutMode): number {
|
|
|
29
29
|
return Math.max(1, cap - BORDER_VERTICAL_OVERHEAD - NOTES_AFFORDANCE_OVERHEAD);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
/**
|
|
33
|
+
* Rows a preview block uses for `rawRows` of content. Unconstrained (no `maxRows`), content is
|
|
34
|
+
* capped by the layout's fixed budget and the notes affordance is kept. Under a `maxRows`
|
|
35
|
+
* allowance that the full block would exceed, the affordance (2 rows — the footer hint already
|
|
36
|
+
* names the notes key) goes first, then content shrinks so the box still closes with its
|
|
37
|
+
* "N lines hidden" count. Undefined when not even one content row fits inside a border.
|
|
38
|
+
*/
|
|
39
|
+
function fitBlock(
|
|
40
|
+
rawRows: number,
|
|
41
|
+
mode: PreviewLayoutMode,
|
|
42
|
+
maxRows: number | undefined,
|
|
43
|
+
): { contentRows: number; affordance: boolean } | undefined {
|
|
44
|
+
const contentRows = Math.min(rawRows, contentBudgetFor(mode));
|
|
45
|
+
if (maxRows === undefined || BORDER_VERTICAL_OVERHEAD + contentRows + NOTES_AFFORDANCE_OVERHEAD <= maxRows) {
|
|
46
|
+
return { contentRows, affordance: true };
|
|
47
|
+
}
|
|
48
|
+
const fitted = Math.min(contentRows, maxRows - BORDER_VERTICAL_OVERHEAD);
|
|
49
|
+
return fitted >= 1 ? { contentRows: fitted, affordance: false } : undefined;
|
|
50
|
+
}
|
|
51
|
+
|
|
32
52
|
/** Inner (padding-aware) content width for a total block width. */
|
|
33
53
|
function innerWidthFor(width: number): number {
|
|
34
54
|
return Math.max(1, width - BORDER_HORIZONTAL_OVERHEAD - 2 * BORDER_INNER_PADDING_HORIZONTAL);
|
|
@@ -72,23 +92,23 @@ export class PreviewBlockRenderer {
|
|
|
72
92
|
}
|
|
73
93
|
|
|
74
94
|
/**
|
|
75
|
-
* Height contribution of the preview block
|
|
76
|
-
*
|
|
77
|
-
*
|
|
95
|
+
* Height contribution of the preview block — always equal to `renderBlock(...).length`
|
|
96
|
+
* for the same arguments (the affordance overhead is not gated by `focused`/`notesVisible`).
|
|
97
|
+
* `maxRows` is the row allowance the dialog can give the block; see `fitBlock`.
|
|
78
98
|
*/
|
|
79
|
-
blockHeight(width: number, optionIndex: number, mode: PreviewLayoutMode): number {
|
|
80
|
-
const
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
const contentRows = Math.min(rawRows, contentBudget);
|
|
84
|
-
return BORDER_VERTICAL_OVERHEAD + contentRows + NOTES_AFFORDANCE_OVERHEAD;
|
|
99
|
+
blockHeight(width: number, optionIndex: number, mode: PreviewLayoutMode, maxRows?: number): number {
|
|
100
|
+
const rawRows = this.cache.bodyFor(optionIndex, innerWidthFor(width)).length;
|
|
101
|
+
const fit = fitBlock(rawRows, mode, maxRows);
|
|
102
|
+
return fit ? BORDER_VERTICAL_OVERHEAD + fit.contentRows + (fit.affordance ? NOTES_AFFORDANCE_OVERHEAD : 0) : 0;
|
|
85
103
|
}
|
|
86
104
|
|
|
87
105
|
/**
|
|
88
|
-
* Render the
|
|
89
|
-
* `focused` and `notesVisible` together gate the affordance
|
|
90
|
-
* focused option carries a preview AND notes mode is inactive)
|
|
91
|
-
* emitted (
|
|
106
|
+
* Render the preview block at `width`: bordered box, then (when it fits) a blank separator
|
|
107
|
+
* and the notes-affordance row. `focused` and `notesVisible` together gate the affordance
|
|
108
|
+
* text (visible only when the focused option carries a preview AND notes mode is inactive);
|
|
109
|
+
* its row is emitted (empty when gated) whenever the block keeps it, so the row count only
|
|
110
|
+
* depends on the fit. Under a `maxRows` allowance the box always closes and its bottom border
|
|
111
|
+
* counts the lines left out; with no room for a box the block is empty.
|
|
92
112
|
*/
|
|
93
113
|
renderBlock(
|
|
94
114
|
width: number,
|
|
@@ -96,18 +116,19 @@ export class PreviewBlockRenderer {
|
|
|
96
116
|
mode: PreviewLayoutMode,
|
|
97
117
|
focused: boolean,
|
|
98
118
|
notesVisible: boolean,
|
|
119
|
+
maxRows?: number,
|
|
99
120
|
): string[] {
|
|
100
|
-
const contentBudget = contentBudgetFor(mode);
|
|
101
121
|
const maxInnerWidth = innerWidthFor(width);
|
|
102
|
-
|
|
103
122
|
const raw = this.cache.bodyFor(optionIndex, maxInnerWidth);
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
const
|
|
123
|
+
const fit = fitBlock(raw.length, mode, maxRows);
|
|
124
|
+
if (!fit) return [];
|
|
125
|
+
const hidden = raw.length - fit.contentRows;
|
|
126
|
+
const contentLines = hidden > 0 ? raw.slice(0, fit.contentRows) : raw;
|
|
107
127
|
|
|
108
128
|
const { boxWidth } = computeBoxDimensions(contentLines, maxInnerWidth);
|
|
109
129
|
const colorFn = (s: string) => this.theme.fg("accent", s);
|
|
110
130
|
const boxedLines = renderBorderedBox(contentLines, boxWidth, colorFn, hidden);
|
|
131
|
+
if (!fit.affordance) return boxedLines;
|
|
111
132
|
|
|
112
133
|
const showAffordance = focused && !notesVisible && this.cache.has(optionIndex);
|
|
113
134
|
const affordance = showAffordance
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import type { Theme } from "@earendil-works/pi-coding-agent";
|
|
1
2
|
import { type Component, truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
|
|
2
3
|
import type { QuestionData } from "../../../tool/types.js";
|
|
4
|
+
import { windowLines } from "../../scroll-window.js";
|
|
3
5
|
import type { StatefulView } from "../../stateful-view.js";
|
|
4
6
|
import type { OptionListView } from "../option-list-view.js";
|
|
5
7
|
import type { PreviewBlockRenderer } from "./preview-block-renderer.js";
|
|
@@ -12,6 +14,9 @@ import {
|
|
|
12
14
|
STACKED_GAP_ROWS,
|
|
13
15
|
} from "./preview-layout-decider.js";
|
|
14
16
|
|
|
17
|
+
/** Smallest preview box worth showing: top border, one content line, bottom border. */
|
|
18
|
+
const MIN_BOX_ROWS = 3;
|
|
19
|
+
|
|
15
20
|
// ----- Re-exports for test imports — keep `./preview-pane.js` as the public surface -----
|
|
16
21
|
export {
|
|
17
22
|
MAX_PREVIEW_HEIGHT_SIDE_BY_SIDE,
|
|
@@ -59,6 +64,7 @@ export interface PreviewPaneProps {
|
|
|
59
64
|
|
|
60
65
|
export interface PreviewPaneConfig {
|
|
61
66
|
question: QuestionData;
|
|
67
|
+
theme: Theme;
|
|
62
68
|
getTerminalWidth: () => number;
|
|
63
69
|
optionListView: OptionListView;
|
|
64
70
|
previewBlock: PreviewBlockRenderer;
|
|
@@ -81,7 +87,15 @@ export class PreviewPane implements StatefulView<PreviewPaneProps>, Component {
|
|
|
81
87
|
private readonly getTerminalWidth: () => number;
|
|
82
88
|
private readonly optionListView: OptionListView;
|
|
83
89
|
private readonly previewBlock: PreviewBlockRenderer;
|
|
90
|
+
private readonly theme: Theme;
|
|
84
91
|
private props: PreviewPaneProps;
|
|
92
|
+
/**
|
|
93
|
+
* Rows the dialog can give this body this frame, set by `DialogView` before each render;
|
|
94
|
+
* undefined when unconstrained. A body taller than this fits itself instead of being cut
|
|
95
|
+
* by the dialog's scroll window: the options scroll within their column around the focused
|
|
96
|
+
* option, and the preview box shrinks but always closes (#210).
|
|
97
|
+
*/
|
|
98
|
+
private rowAllowance: number | undefined;
|
|
85
99
|
/**
|
|
86
100
|
* Cross-tab max left-width getter. Set exactly once by `buildQuestionnaire.injectGlobalLeftWidth`
|
|
87
101
|
* before any render. Initialized to a throwing sentinel so missing injection is a hard fail
|
|
@@ -96,6 +110,7 @@ export class PreviewPane implements StatefulView<PreviewPaneProps>, Component {
|
|
|
96
110
|
this.getTerminalWidth = config.getTerminalWidth;
|
|
97
111
|
this.optionListView = config.optionListView;
|
|
98
112
|
this.previewBlock = config.previewBlock;
|
|
113
|
+
this.theme = config.theme;
|
|
99
114
|
this.props = { notesVisible: false, selectedIndex: 0, focused: false, inputMode: false };
|
|
100
115
|
}
|
|
101
116
|
|
|
@@ -111,6 +126,11 @@ export class PreviewPane implements StatefulView<PreviewPaneProps>, Component {
|
|
|
111
126
|
this.props = props;
|
|
112
127
|
}
|
|
113
128
|
|
|
129
|
+
/** Render-time geometry from `DialogView` (not canonical state, so not a prop). */
|
|
130
|
+
setRowAllowance(rows: number | undefined): void {
|
|
131
|
+
this.rowAllowance = rows;
|
|
132
|
+
}
|
|
133
|
+
|
|
114
134
|
handleInput(_data: string): void {}
|
|
115
135
|
|
|
116
136
|
invalidate(): void {
|
|
@@ -128,21 +148,98 @@ export class PreviewPane implements StatefulView<PreviewPaneProps>, Component {
|
|
|
128
148
|
// Side-by-side + preview block resume verbatim on nav-away (inputMode clears).
|
|
129
149
|
if (this.props.inputMode) return this.optionListView.render(width);
|
|
130
150
|
|
|
151
|
+
return this.layout(width).lines;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Options + preview for the current layout mode, fitted to `rowAllowance` when set. The
|
|
156
|
+
* returned focus range is in the same row coordinates as `lines`, so `render`,
|
|
157
|
+
* `focusedItemRowRange` and `naturalHeight` agree by construction.
|
|
158
|
+
*/
|
|
159
|
+
private layout(width: number): { lines: string[]; focus: [number, number] | undefined } {
|
|
131
160
|
const mode = decideLayout(this.getTerminalWidth(), width);
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
161
|
+
return mode === "side-by-side" ? this.layoutSideBySide(width, mode) : this.layoutStacked(width, mode);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Stacked: options, a blank gap, then the preview block. When that exceeds the allowance,
|
|
166
|
+
* keep the focused option (plus a row either side for the overflow arrows) and give the
|
|
167
|
+
* preview the rest, so the preview of the option being considered stays in view instead
|
|
168
|
+
* of falling below the dialog's scroll window.
|
|
169
|
+
*/
|
|
170
|
+
private layoutStacked(
|
|
171
|
+
width: number,
|
|
172
|
+
mode: PreviewLayoutMode,
|
|
173
|
+
): { lines: string[]; focus: [number, number] | undefined } {
|
|
174
|
+
const { selectedIndex, focused, notesVisible } = this.props;
|
|
175
|
+
const options = this.optionListView.render(width);
|
|
176
|
+
const focus = this.optionListView.focusedItemRowRange(width);
|
|
177
|
+
const gap = Array<string>(STACKED_GAP_ROWS).fill("");
|
|
178
|
+
const allowance = this.rowAllowance;
|
|
179
|
+
const fullBlock = this.previewBlock.blockHeight(width, selectedIndex, mode);
|
|
180
|
+
if (allowance === undefined || options.length + STACKED_GAP_ROWS + fullBlock <= allowance) {
|
|
181
|
+
return {
|
|
182
|
+
lines: [
|
|
183
|
+
...options,
|
|
184
|
+
...gap,
|
|
185
|
+
...this.previewBlock.renderBlock(width, selectedIndex, mode, focused, notesVisible),
|
|
186
|
+
],
|
|
187
|
+
focus,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
// Prefer keeping a row either side of the focused option for the overflow arrows; give
|
|
191
|
+
// those up only when they are what keeps the preview box (border + 1 line) from fitting.
|
|
192
|
+
const focusRows = focus ? focus[1] - focus[0] : 1;
|
|
193
|
+
const previewRowsWith = (optionsFloor: number) =>
|
|
194
|
+
Math.min(fullBlock, allowance - STACKED_GAP_ROWS - Math.min(options.length, optionsFloor));
|
|
195
|
+
const roomy = previewRowsWith(focusRows + 2);
|
|
196
|
+
const previewRows = roomy >= MIN_BOX_ROWS ? roomy : previewRowsWith(focusRows);
|
|
197
|
+
const block = this.previewBlock.renderBlock(width, selectedIndex, mode, focused, notesVisible, previewRows);
|
|
198
|
+
const optionRows = allowance - (block.length > 0 ? STACKED_GAP_ROWS + block.length : 0);
|
|
199
|
+
const windowed = windowLines(options, Math.max(1, optionRows), focus, this.theme);
|
|
200
|
+
return {
|
|
201
|
+
lines: block.length > 0 ? [...windowed.lines, ...gap, ...block] : windowed.lines,
|
|
202
|
+
focus: windowed.focus,
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Side-by-side: options column left, preview block right. Under an allowance the options
|
|
208
|
+
* column scrolls around the focused option and the preview block shrinks, so neither
|
|
209
|
+
* column exceeds it and the dialog never slices through the preview box.
|
|
210
|
+
*/
|
|
211
|
+
private layoutSideBySide(
|
|
212
|
+
width: number,
|
|
213
|
+
mode: PreviewLayoutMode,
|
|
214
|
+
): { lines: string[]; focus: [number, number] | undefined } {
|
|
215
|
+
const adaptiveLeft = this.getAdaptiveLeft(width);
|
|
216
|
+
const { leftWidth, rightWidth, gap } = columnWidths(width, adaptiveLeft);
|
|
217
|
+
const allowance = this.rowAllowance;
|
|
218
|
+
const left =
|
|
219
|
+
allowance === undefined
|
|
220
|
+
? {
|
|
221
|
+
lines: this.optionListView.render(leftWidth),
|
|
222
|
+
focus: this.optionListView.focusedItemRowRange(leftWidth),
|
|
223
|
+
}
|
|
224
|
+
: windowLines(
|
|
225
|
+
this.optionListView.render(leftWidth),
|
|
226
|
+
allowance,
|
|
227
|
+
this.optionListView.focusedItemRowRange(leftWidth),
|
|
228
|
+
this.theme,
|
|
229
|
+
);
|
|
230
|
+
const rightLines = this.renderPaddedPreviewLines(rightWidth, mode, allowance);
|
|
231
|
+
const rows = Math.max(left.lines.length, rightLines.length);
|
|
232
|
+
const gapStr = " ".repeat(gap);
|
|
233
|
+
const out: string[] = [];
|
|
234
|
+
for (let i = 0; i < rows; i++) {
|
|
235
|
+
const leftRaw = left.lines[i] ?? "";
|
|
236
|
+
const rightRaw = rightLines[i] ?? "";
|
|
237
|
+
const leftClamped = truncateToWidth(leftRaw, leftWidth, "");
|
|
238
|
+
const leftPad = " ".repeat(Math.max(0, leftWidth - visibleWidth(leftClamped)));
|
|
239
|
+
const joined = `${leftClamped}${leftPad}${gapStr}${rightRaw}`;
|
|
240
|
+
out.push(truncateToWidth(joined, width, ""));
|
|
241
|
+
}
|
|
242
|
+
return { lines: out, focus: left.focus };
|
|
146
243
|
}
|
|
147
244
|
|
|
148
245
|
focusedItemRowRange(width: number): [number, number] {
|
|
@@ -151,11 +248,7 @@ export class PreviewPane implements StatefulView<PreviewPaneProps>, Component {
|
|
|
151
248
|
// `inputMode`: compute the focused row range against the FULL pane width (not the
|
|
152
249
|
// side-by-side leftWidth), mirroring `render`'s full-width option list.
|
|
153
250
|
if (this.props.inputMode) return this.optionListView.focusedItemRowRange(width);
|
|
154
|
-
|
|
155
|
-
if (mode === "stacked") return this.optionListView.focusedItemRowRange(width);
|
|
156
|
-
const adaptiveLeft = this.getAdaptiveLeft(width);
|
|
157
|
-
const { leftWidth } = columnWidths(width, adaptiveLeft);
|
|
158
|
-
return this.optionListView.focusedItemRowRange(leftWidth);
|
|
251
|
+
return this.layout(width).focus ?? [0, 1];
|
|
159
252
|
}
|
|
160
253
|
|
|
161
254
|
naturalHeight(width: number): number {
|
|
@@ -164,6 +257,7 @@ export class PreviewPane implements StatefulView<PreviewPaneProps>, Component {
|
|
|
164
257
|
// `inputMode`: height is the full-width option list only (no preview block) — preserves
|
|
165
258
|
// the `naturalHeight === render.length` parity invariant.
|
|
166
259
|
if (this.props.inputMode) return this.optionListView.render(width).length;
|
|
260
|
+
if (this.rowAllowance !== undefined) return this.layout(width).lines.length;
|
|
167
261
|
const mode = decideLayout(this.getTerminalWidth(), width);
|
|
168
262
|
const adaptiveLeft = this.getAdaptiveLeft(width);
|
|
169
263
|
const { optionsWidth, previewWidth } = bodyWidths(width, mode, adaptiveLeft);
|
|
@@ -188,30 +282,15 @@ export class PreviewPane implements StatefulView<PreviewPaneProps>, Component {
|
|
|
188
282
|
const h = this.previewBlock.blockHeight(previewWidth, i, mode);
|
|
189
283
|
if (h > maxPreviewBlock) maxPreviewBlock = h;
|
|
190
284
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
const { leftWidth, rightWidth, gap } = columnWidths(width, adaptiveLeft);
|
|
198
|
-
const leftLines = this.optionListView.render(leftWidth);
|
|
199
|
-
const rightLines = this.renderPaddedPreviewLines(rightWidth, mode);
|
|
200
|
-
const rows = Math.max(leftLines.length, rightLines.length);
|
|
201
|
-
const gapStr = " ".repeat(gap);
|
|
202
|
-
const out: string[] = [];
|
|
203
|
-
for (let i = 0; i < rows; i++) {
|
|
204
|
-
const leftRaw = leftLines[i] ?? "";
|
|
205
|
-
const rightRaw = rightLines[i] ?? "";
|
|
206
|
-
const leftClamped = truncateToWidth(leftRaw, leftWidth, "");
|
|
207
|
-
const leftPad = " ".repeat(Math.max(0, leftWidth - visibleWidth(leftClamped)));
|
|
208
|
-
const joined = `${leftClamped}${leftPad}${gapStr}${rightRaw}`;
|
|
209
|
-
out.push(truncateToWidth(joined, width, ""));
|
|
210
|
-
}
|
|
211
|
-
return out;
|
|
285
|
+
const max =
|
|
286
|
+
mode === "side-by-side"
|
|
287
|
+
? Math.max(optionsHeight, maxPreviewBlock)
|
|
288
|
+
: optionsHeight + STACKED_GAP_ROWS + maxPreviewBlock;
|
|
289
|
+
// A fitted body never exceeds the allowance, whichever option is focused.
|
|
290
|
+
return this.rowAllowance === undefined ? max : Math.min(max, this.rowAllowance);
|
|
212
291
|
}
|
|
213
292
|
|
|
214
|
-
private renderPaddedPreviewLines(colWidth: number, mode: PreviewLayoutMode): string[] {
|
|
293
|
+
private renderPaddedPreviewLines(colWidth: number, mode: PreviewLayoutMode, maxRows: number | undefined): string[] {
|
|
215
294
|
const inner = Math.max(1, colWidth - PREVIEW_PADDING_LEFT);
|
|
216
295
|
const contentLines = this.previewBlock.renderBlock(
|
|
217
296
|
inner,
|
|
@@ -219,6 +298,7 @@ export class PreviewPane implements StatefulView<PreviewPaneProps>, Component {
|
|
|
219
298
|
mode,
|
|
220
299
|
this.props.focused,
|
|
221
300
|
this.props.notesVisible,
|
|
301
|
+
maxRows,
|
|
222
302
|
);
|
|
223
303
|
const boxWidth = Math.max(1, visibleWidth(contentLines[0] ?? ""));
|
|
224
304
|
const boxAlignedPad = Math.max(PREVIEW_PADDING_LEFT, colWidth - boxWidth);
|
package/view/dialog-builder.ts
CHANGED
|
@@ -5,6 +5,7 @@ import type { QuestionnaireState } from "../state/state.js";
|
|
|
5
5
|
import type { QuestionData } from "../tool/types.js";
|
|
6
6
|
import type { PreviewPaneProps } from "./components/preview/preview-pane.js";
|
|
7
7
|
import type { TabBar } from "./components/tab-bar.js";
|
|
8
|
+
import { computeScrollStart, decorateOverflow } from "./scroll-window.js";
|
|
8
9
|
import type { StatefulView } from "./stateful-view.js";
|
|
9
10
|
import type { TabComponents } from "./tab-components.js";
|
|
10
11
|
import { QuestionTabStrategy, SubmitTabStrategy, type TabContentStrategy } from "./tab-content-strategy.js";
|
|
@@ -64,10 +65,6 @@ export const INCOMPLETE_WARNING_PREFIX = "⚠ Answer remaining questions before
|
|
|
64
65
|
*/
|
|
65
66
|
const MIN_SCROLL_ROWS_WITH_PINNED_HEADING = 3;
|
|
66
67
|
|
|
67
|
-
const OVERFLOW_UP = "↑";
|
|
68
|
-
const OVERFLOW_DOWN = "↓";
|
|
69
|
-
const OVERFLOW_BOTH = "↕";
|
|
70
|
-
|
|
71
68
|
/** No-overflow path: append the residual spacer rows after the footer. */
|
|
72
69
|
function renderFitsTerminal(natural: string[], spacerRows: number): string[] {
|
|
73
70
|
return spacerRows > 0 ? [...natural, ...Array<string>(spacerRows).fill("")] : natural;
|
|
@@ -79,36 +76,6 @@ function renderChromeOnly(natural: string[], topFixed: number, bottomFixed: numb
|
|
|
79
76
|
return chromeOnly.length > termRows ? chromeOnly.slice(0, termRows) : chromeOnly;
|
|
80
77
|
}
|
|
81
78
|
|
|
82
|
-
/** Scroll window start, centered on the focused option; top-anchored when there is no interactive focus. */
|
|
83
|
-
function computeScrollStart(
|
|
84
|
-
bodyRange: [number, number] | undefined,
|
|
85
|
-
rowsBeforeBody: number,
|
|
86
|
-
availableMiddle: number,
|
|
87
|
-
middleRows: number,
|
|
88
|
-
): number {
|
|
89
|
-
if (!bodyRange) return 0;
|
|
90
|
-
const focusedRowInMiddle = rowsBeforeBody + bodyRange[0];
|
|
91
|
-
const focusedHeight = bodyRange[1] - bodyRange[0];
|
|
92
|
-
// Center the focused item vertically in the available middle space.
|
|
93
|
-
const idealStart = focusedRowInMiddle - Math.floor(Math.max(0, availableMiddle - focusedHeight) / 2);
|
|
94
|
-
return Math.max(0, Math.min(idealStart, middleRows - availableMiddle));
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/** Mark the scroll window edges with overflow arrows; combined ↕ on a single-row middle. */
|
|
98
|
-
function decorateOverflow(scrollableMiddle: string[], hasUp: boolean, hasDown: boolean, theme: Theme): void {
|
|
99
|
-
if (hasUp && hasDown && scrollableMiddle.length === 1) {
|
|
100
|
-
// Single-row middle: combined ↕ avoids the prior collision where ↓ overwrote ↑.
|
|
101
|
-
scrollableMiddle[0] = theme.fg("dim", OVERFLOW_BOTH);
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
if (hasUp && scrollableMiddle.length > 0) {
|
|
105
|
-
scrollableMiddle[0] = theme.fg("dim", OVERFLOW_UP);
|
|
106
|
-
}
|
|
107
|
-
if (hasDown && scrollableMiddle.length > 0) {
|
|
108
|
-
scrollableMiddle[scrollableMiddle.length - 1] = theme.fg("dim", OVERFLOW_DOWN);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
79
|
export type DialogState = QuestionnaireState;
|
|
113
80
|
|
|
114
81
|
/** Per-tick projection of dialog state. Written by the adapter; read by the strategy thunk. */
|
|
@@ -202,14 +169,22 @@ export class DialogView implements StatefulView<DialogProps> {
|
|
|
202
169
|
|
|
203
170
|
// Cache heading rows (avoid double construction in render and container build).
|
|
204
171
|
const headingRowCache = strategy.headingRows(state);
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
const natural = this.buildContainerFromStrategy(strategy, headingRowCache).render(width);
|
|
172
|
+
// Rendered rows, not components: a long question wraps.
|
|
173
|
+
const headingHeight = headingRowCache.reduce((rows, c) => rows + c.render(width).length, 0);
|
|
208
174
|
|
|
209
175
|
// Fixed region sizes (deterministic from structure).
|
|
210
176
|
// TabBar.render() returns [tabLine, ""] — always 2 rows.
|
|
211
177
|
const topFixed = 1 + (this.config.isMulti && this.config.tabBar ? 2 : 0) + 1;
|
|
212
178
|
const bottomFixed = 1 + strategy.footerRowCount;
|
|
179
|
+
const termRows = this.config.getTerminalRows();
|
|
180
|
+
|
|
181
|
+
this.allotBodyRows(
|
|
182
|
+
onSubmit,
|
|
183
|
+
termRows - topFixed - headingHeight - bottomFixed - this.rowsAroundBody(strategy, width),
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
// Build container WITHOUT residual spacer — spacer handled below based on overflow.
|
|
187
|
+
const natural = this.buildContainerFromStrategy(strategy, headingRowCache).render(width);
|
|
213
188
|
|
|
214
189
|
// Residual spacer: equalizes total height across tabs (only needed when no overflow).
|
|
215
190
|
const spacerRows = Math.max(
|
|
@@ -220,17 +195,17 @@ export class DialogView implements StatefulView<DialogProps> {
|
|
|
220
195
|
strategy.footerRowCount,
|
|
221
196
|
);
|
|
222
197
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
198
|
+
// The spacer is padding for a stable cross-tab footprint, not content: when only the
|
|
199
|
+
// padding overflows, clamp it rather than entering the scroll partition, which assumes
|
|
200
|
+
// the middle region itself is longer than the window (#260).
|
|
201
|
+
if (natural.length <= termRows) {
|
|
202
|
+
return renderFitsTerminal(natural, Math.min(spacerRows, termRows - natural.length));
|
|
227
203
|
}
|
|
228
204
|
|
|
229
205
|
// OVERFLOW — apply 3-region partition with scroll-to-focus. The heading joins the
|
|
230
206
|
// fixed top whenever the body keeps a usable window, so the question being answered
|
|
231
207
|
// never scrolls out of view; heading height is measured in rendered rows, since a
|
|
232
208
|
// long question wraps.
|
|
233
|
-
const headingHeight = headingRowCache.reduce((rows, c) => rows + c.render(width).length, 0);
|
|
234
209
|
const pinHeading = termRows - topFixed - headingHeight - bottomFixed >= MIN_SCROLL_ROWS_WITH_PINNED_HEADING;
|
|
235
210
|
const top = pinHeading ? topFixed + headingHeight : topFixed;
|
|
236
211
|
const middleRows = natural.length - top - bottomFixed;
|
|
@@ -239,18 +214,23 @@ export class DialogView implements StatefulView<DialogProps> {
|
|
|
239
214
|
return renderChromeOnly(natural, top, bottomFixed, termRows);
|
|
240
215
|
}
|
|
241
216
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
);
|
|
248
|
-
const scrollableMiddle = natural.slice(top + scrollStart, top + scrollStart +
|
|
217
|
+
// Never slice past the middle region into the bottom-fixed rows, which are appended
|
|
218
|
+
// below — that would draw the bottom border and hint twice (#260).
|
|
219
|
+
const windowRows = Math.min(availableMiddle, middleRows);
|
|
220
|
+
const rowsBeforeBody = pinHeading ? 0 : headingHeight;
|
|
221
|
+
const focusedRange = strategy.focusedItemRowRange(width, state);
|
|
222
|
+
const scrollStart = computeScrollStart(focusedRange, rowsBeforeBody, windowRows, middleRows);
|
|
223
|
+
const scrollableMiddle = natural.slice(top + scrollStart, top + scrollStart + windowRows);
|
|
224
|
+
const focusedInWindow: [number, number] | undefined = focusedRange && [
|
|
225
|
+
rowsBeforeBody + focusedRange[0] - scrollStart,
|
|
226
|
+
rowsBeforeBody + focusedRange[1] - scrollStart,
|
|
227
|
+
];
|
|
249
228
|
decorateOverflow(
|
|
250
229
|
scrollableMiddle,
|
|
251
230
|
scrollStart > 0,
|
|
252
|
-
scrollStart +
|
|
231
|
+
scrollStart + windowRows < middleRows,
|
|
253
232
|
this.config.theme,
|
|
233
|
+
focusedInWindow,
|
|
254
234
|
);
|
|
255
235
|
|
|
256
236
|
const result = [...natural.slice(0, top), ...scrollableMiddle, ...natural.slice(natural.length - bottomFixed)];
|
|
@@ -259,6 +239,26 @@ export class DialogView implements StatefulView<DialogProps> {
|
|
|
259
239
|
return result.length > termRows ? result.slice(0, termRows) : result;
|
|
260
240
|
}
|
|
261
241
|
|
|
242
|
+
/** Rows between the body and the bottom border: the body's trailing Spacer(1) plus any mid rows (e.g. the notes editor). */
|
|
243
|
+
private rowsAroundBody(strategy: TabContentStrategy, width: number): number {
|
|
244
|
+
return 1 + strategy.midRows(this.liveProps.state).reduce((rows, c) => rows + c.render(width).length, 0);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Hand the active question's preview pane the rows its body may use this frame, so a body
|
|
249
|
+
* taller than the space fits itself — options scroll in their column, the preview box
|
|
250
|
+
* shrinks but closes — instead of the scroll window below slicing through it (#210).
|
|
251
|
+
* Other tabs' panes are cleared so a stale allowance never skews the cross-tab height.
|
|
252
|
+
* Below `MIN_SCROLL_ROWS_WITH_PINNED_HEADING` the dialog's own scroll window takes over.
|
|
253
|
+
*/
|
|
254
|
+
private allotBodyRows(onSubmit: boolean, bodyRows: number): void {
|
|
255
|
+
const active =
|
|
256
|
+
onSubmit || bodyRows < MIN_SCROLL_ROWS_WITH_PINNED_HEADING ? undefined : this.liveProps.activePreviewPane;
|
|
257
|
+
for (const tab of this.config.tabsByIndex) {
|
|
258
|
+
tab.preview?.setRowAllowance?.(tab.preview === active ? bodyRows : undefined);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
262
|
private buildContainerFromStrategy(strategy: TabContentStrategy, headingRowCache: Component[]): Container {
|
|
263
263
|
const { theme, isMulti, tabBar } = this.config;
|
|
264
264
|
const state = this.liveProps.state;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { Theme } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Scroll-window row math shared by `DialogView` (the dialog's middle region) and
|
|
5
|
+
* `PreviewPane` (an options column fitted to the row allowance the dialog gives it) —
|
|
6
|
+
* one implementation, so both windows centre, clamp and mark overflow identically.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const OVERFLOW_UP = "↑";
|
|
10
|
+
const OVERFLOW_DOWN = "↓";
|
|
11
|
+
const OVERFLOW_BOTH = "↕";
|
|
12
|
+
|
|
13
|
+
/** Scroll window start, centered on the focused option; top-anchored when there is no interactive focus. */
|
|
14
|
+
export function computeScrollStart(
|
|
15
|
+
bodyRange: [number, number] | undefined,
|
|
16
|
+
rowsBeforeBody: number,
|
|
17
|
+
availableMiddle: number,
|
|
18
|
+
middleRows: number,
|
|
19
|
+
): number {
|
|
20
|
+
if (!bodyRange) return 0;
|
|
21
|
+
const focusedRowInMiddle = rowsBeforeBody + bodyRange[0];
|
|
22
|
+
const focusedHeight = bodyRange[1] - bodyRange[0];
|
|
23
|
+
// Center the focused item vertically in the available middle space.
|
|
24
|
+
const idealStart = focusedRowInMiddle - Math.floor(Math.max(0, availableMiddle - focusedHeight) / 2);
|
|
25
|
+
return Math.max(0, Math.min(idealStart, middleRows - availableMiddle));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Mark the scroll window edges with overflow arrows; combined ↕ on a single-row middle.
|
|
30
|
+
* An arrow replaces the row it lands on, so rows inside `protectedRows` (the focused item,
|
|
31
|
+
* in window coordinates, end-exclusive) are never drawn over — losing the affordance beats
|
|
32
|
+
* losing the row the user is on (#261).
|
|
33
|
+
*/
|
|
34
|
+
export function decorateOverflow(
|
|
35
|
+
scrollableMiddle: string[],
|
|
36
|
+
hasUp: boolean,
|
|
37
|
+
hasDown: boolean,
|
|
38
|
+
theme: Theme,
|
|
39
|
+
protectedRows: readonly [number, number] | undefined,
|
|
40
|
+
): void {
|
|
41
|
+
const drawable = (row: number) => !protectedRows || row < protectedRows[0] || row >= protectedRows[1];
|
|
42
|
+
if (hasUp && hasDown && scrollableMiddle.length === 1) {
|
|
43
|
+
// Single-row middle: combined ↕ avoids the prior collision where ↓ overwrote ↑.
|
|
44
|
+
if (drawable(0)) scrollableMiddle[0] = theme.fg("dim", OVERFLOW_BOTH);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (hasUp && scrollableMiddle.length > 0 && drawable(0)) {
|
|
48
|
+
scrollableMiddle[0] = theme.fg("dim", OVERFLOW_UP);
|
|
49
|
+
}
|
|
50
|
+
const last = scrollableMiddle.length - 1;
|
|
51
|
+
if (hasDown && last > 0 && drawable(last)) {
|
|
52
|
+
scrollableMiddle[last] = theme.fg("dim", OVERFLOW_DOWN);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Window `lines` to at most `rows` rows, centred on `focus` (end-exclusive row range),
|
|
58
|
+
* with overflow arrows that never cover the focused rows. Returns the visible lines and
|
|
59
|
+
* the focus range in window coordinates. Lines that already fit are returned unchanged.
|
|
60
|
+
*/
|
|
61
|
+
export function windowLines(
|
|
62
|
+
lines: readonly string[],
|
|
63
|
+
rows: number,
|
|
64
|
+
focus: [number, number] | undefined,
|
|
65
|
+
theme: Theme,
|
|
66
|
+
): { lines: string[]; focus: [number, number] | undefined } {
|
|
67
|
+
if (lines.length <= rows) return { lines: [...lines], focus };
|
|
68
|
+
const start = computeScrollStart(focus, 0, rows, lines.length);
|
|
69
|
+
const visible = lines.slice(start, start + rows);
|
|
70
|
+
const inWindow: [number, number] | undefined = focus && [focus[0] - start, focus[1] - start];
|
|
71
|
+
decorateOverflow(visible, start > 0, start + rows < lines.length, theme, inWindow);
|
|
72
|
+
return { lines: visible, focus: inWindow };
|
|
73
|
+
}
|
|
@@ -243,7 +243,9 @@ export class SubmitTabStrategy implements TabContentStrategy {
|
|
|
243
243
|
"warning",
|
|
244
244
|
`${t("review.incomplete", INCOMPLETE_WARNING_PREFIX)} ${missing.join(", ")}`,
|
|
245
245
|
);
|
|
246
|
-
|
|
246
|
+
// One row, never wrapped: `footerRowCount` counts it as one, and a wrapped prompt
|
|
247
|
+
// (long list of unanswered headers) would desync the chrome's row math (#261).
|
|
248
|
+
const out: Component[] = [new Spacer(1), new OneLineClippedText(promptText, 1)];
|
|
247
249
|
if (this.config.submitPicker) {
|
|
248
250
|
out.push(this.config.submitPicker);
|
|
249
251
|
} else {
|