@lune_99/pi-ask-question 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +38 -2
- package/README.md +31 -22
- package/package.json +6 -6
- package/src/commands/question.ts +17 -7
- package/src/core/question-delivery.ts +81 -29
- package/src/core/question-format.ts +36 -11
- package/src/core/questionManager.ts +302 -78
- package/src/index.ts +64 -35
- package/src/tools/ask-user-questions.ts +142 -56
- package/src/tools/withdraw-user-questions.ts +169 -0
- package/src/tui/dock-line.ts +42 -0
- package/src/tui/panel/clipboard-paste.ts +124 -0
- package/src/tui/panel/question-panel-controller.ts +13 -12
- package/src/tui/panel/question-panel-renderer.ts +180 -126
- package/src/tui/panel/question-panel.ts +259 -97
- package/src/tui/preview/preview-box.ts +22 -15
- package/src/tui/preview/preview-layout.ts +7 -4
- package/src/tui/preview/preview-renderer.ts +6 -1
- package/src/tui/question-answer-message.ts +6 -4
- package/src/tui/question-dock-contribution.ts +63 -23
- package/src/tui/question-dock.ts +58 -21
- package/docs/question-answer-row.png +0 -0
- package/docs/question-answer-row.svg +0 -16
- package/docs/question-dock.png +0 -0
- package/docs/question-dock.svg +0 -8
- package/docs/question-panel.svg +0 -58
- package/src/core/question-notification.ts +0 -34
|
@@ -2,18 +2,15 @@
|
|
|
2
2
|
* Terminal renderer of the question panel: frame, header/footer hints, the focused question,
|
|
3
3
|
* its option rows, the submit summary and the option preview pane.
|
|
4
4
|
*
|
|
5
|
-
* It reads the
|
|
6
|
-
* interaction, the draft and the editor, and hands the renderer
|
|
7
|
-
* read from the
|
|
5
|
+
* It reads the questions and the draft through the controller's read-only view and never
|
|
6
|
+
* changes them; the panel owns the interaction, the draft and the editor, and hands the renderer
|
|
7
|
+
* the transient state it cannot read from the view (`inputMode`, the editor component and the
|
|
8
|
+
* body budget).
|
|
8
9
|
*
|
|
9
|
-
* The renderer's own caches are render state, not session state:
|
|
10
|
-
* preview renderer per question, both dropped by `invalidate()` when the theme changes.
|
|
10
|
+
* The renderer's own caches are render state, not session state: one `displayText` parser and
|
|
11
|
+
* one preview renderer per question, both dropped by `invalidate()` when the theme changes.
|
|
11
12
|
*/
|
|
12
|
-
import {
|
|
13
|
-
getMarkdownTheme,
|
|
14
|
-
type Theme,
|
|
15
|
-
type ThemeColor,
|
|
16
|
-
} from "@earendil-works/pi-coding-agent";
|
|
13
|
+
import { getMarkdownTheme, type Theme, type ThemeColor } from "@earendil-works/pi-coding-agent";
|
|
17
14
|
import {
|
|
18
15
|
CURSOR_MARKER,
|
|
19
16
|
Markdown,
|
|
@@ -24,15 +21,12 @@ import {
|
|
|
24
21
|
|
|
25
22
|
import {
|
|
26
23
|
formatAnswer,
|
|
24
|
+
optionLabel,
|
|
27
25
|
questionHeaderPrefix,
|
|
28
26
|
questionTabLabel,
|
|
29
27
|
summarizeText,
|
|
30
28
|
} from "../../core/question-format.ts";
|
|
31
|
-
import type {
|
|
32
|
-
AskQuestion,
|
|
33
|
-
AskQuestionAnswer,
|
|
34
|
-
AskQuestionRequest,
|
|
35
|
-
} from "../../core/question-types.ts";
|
|
29
|
+
import type { AskQuestion, AskQuestionAnswer } from "../../core/question-types.ts";
|
|
36
30
|
import {
|
|
37
31
|
MIN_BLOCK_ROWS,
|
|
38
32
|
STACKED_GAP_ROWS,
|
|
@@ -43,9 +37,9 @@ import {
|
|
|
43
37
|
} from "../preview/preview-layout.ts";
|
|
44
38
|
import { QuestionPreviewRenderer } from "../preview/preview-renderer.ts";
|
|
45
39
|
import {
|
|
46
|
-
areAllAnswered,
|
|
47
40
|
focusedRowIndex,
|
|
48
41
|
questionRows,
|
|
42
|
+
type QuestionPanelView,
|
|
49
43
|
type QuestionRow,
|
|
50
44
|
} from "./question-panel-controller.ts";
|
|
51
45
|
|
|
@@ -112,7 +106,14 @@ export interface QuestionPanelFrame {
|
|
|
112
106
|
|
|
113
107
|
/** Body-relative positions collected while the body is built. */
|
|
114
108
|
interface BodyMarks {
|
|
115
|
-
preview?: {
|
|
109
|
+
preview?: {
|
|
110
|
+
line: number;
|
|
111
|
+
height: number;
|
|
112
|
+
start: number;
|
|
113
|
+
width: number;
|
|
114
|
+
offset: number;
|
|
115
|
+
maxOffset: number;
|
|
116
|
+
};
|
|
116
117
|
editor?: { line: number; height: number; width: number };
|
|
117
118
|
}
|
|
118
119
|
|
|
@@ -128,16 +129,16 @@ interface RenderedBody {
|
|
|
128
129
|
}
|
|
129
130
|
|
|
130
131
|
export interface QuestionPanelRendererOptions {
|
|
131
|
-
|
|
132
|
+
view: QuestionPanelView;
|
|
132
133
|
theme: Theme;
|
|
133
134
|
}
|
|
134
135
|
|
|
135
136
|
export class QuestionPanelRenderer {
|
|
136
|
-
private readonly
|
|
137
|
+
private readonly view: QuestionPanelView;
|
|
137
138
|
private readonly theme: Theme;
|
|
138
139
|
|
|
139
|
-
|
|
140
|
-
private
|
|
140
|
+
/** One `displayText` parser per question, so switching tabs does not parse it again. */
|
|
141
|
+
private readonly displayMarkdown = new Map<number, Markdown>();
|
|
141
142
|
/**
|
|
142
143
|
* One preview renderer per question: an option index only identifies an option inside its
|
|
143
144
|
* own question, so a renderer must not be shared across tabs.
|
|
@@ -145,7 +146,7 @@ export class QuestionPanelRenderer {
|
|
|
145
146
|
private readonly previewRenderers = new Map<number, QuestionPreviewRenderer>();
|
|
146
147
|
|
|
147
148
|
constructor(options: QuestionPanelRendererOptions) {
|
|
148
|
-
this.
|
|
149
|
+
this.view = options.view;
|
|
149
150
|
this.theme = options.theme;
|
|
150
151
|
}
|
|
151
152
|
|
|
@@ -154,7 +155,7 @@ export class QuestionPanelRenderer {
|
|
|
154
155
|
const contentWidth = innerWidth - 2;
|
|
155
156
|
// The tab strip stays put while the body scrolls. It is the only way to see which
|
|
156
157
|
// questions exist and to reach the others, so it must not scroll out of view.
|
|
157
|
-
const tabs = this.isMultiQuestion
|
|
158
|
+
const tabs = this.view.isMultiQuestion
|
|
158
159
|
? this.renderTabsBlock(contentWidth)
|
|
159
160
|
: { lines: [], spans: [] };
|
|
160
161
|
const bodyRoom = Math.max(1, state.maxBodyHeight - tabs.lines.length);
|
|
@@ -167,7 +168,10 @@ export class QuestionPanelRenderer {
|
|
|
167
168
|
state.bodyScroll,
|
|
168
169
|
body.keep,
|
|
169
170
|
);
|
|
170
|
-
const visible = [
|
|
171
|
+
const visible = [
|
|
172
|
+
...tabs.lines,
|
|
173
|
+
...body.lines.slice(window.offset, window.offset + bodyHeight),
|
|
174
|
+
];
|
|
171
175
|
|
|
172
176
|
while (visible.length < tabs.lines.length + bodyHeight) {
|
|
173
177
|
visible.push("");
|
|
@@ -185,7 +189,9 @@ export class QuestionPanelRenderer {
|
|
|
185
189
|
this.frame(`┌${"─".repeat(innerWidth)}┐`),
|
|
186
190
|
this.frame("│") + this.renderHeader(innerWidth) + this.frame("│"),
|
|
187
191
|
this.frame(`├${"─".repeat(innerWidth)}┤`),
|
|
188
|
-
...visible.map(
|
|
192
|
+
...visible.map(
|
|
193
|
+
(line) => this.frame("│") + this.cell(line, innerWidth) + this.frame("│"),
|
|
194
|
+
),
|
|
189
195
|
this.frame(`├${"─".repeat(innerWidth)}┤`),
|
|
190
196
|
this.frame("│") + this.renderFooter(innerWidth, state.inputMode) + this.frame("│"),
|
|
191
197
|
this.frame(`└${"─".repeat(innerWidth)}┘`),
|
|
@@ -206,7 +212,10 @@ export class QuestionPanelRenderer {
|
|
|
206
212
|
|
|
207
213
|
if (marks.preview) {
|
|
208
214
|
const top = Math.max(marks.preview.line, body.offset);
|
|
209
|
-
const bottom = Math.min(
|
|
215
|
+
const bottom = Math.min(
|
|
216
|
+
marks.preview.line + marks.preview.height,
|
|
217
|
+
body.offset + body.height,
|
|
218
|
+
);
|
|
210
219
|
|
|
211
220
|
if (bottom > top) {
|
|
212
221
|
layout.preview = {
|
|
@@ -233,62 +242,37 @@ export class QuestionPanelRenderer {
|
|
|
233
242
|
}
|
|
234
243
|
|
|
235
244
|
invalidate(): void {
|
|
236
|
-
this.
|
|
237
|
-
this.markdownText = undefined;
|
|
245
|
+
this.displayMarkdown.clear();
|
|
238
246
|
// The renderers hold the markdown theme they were built with, so a theme change has
|
|
239
247
|
// to rebuild them.
|
|
240
248
|
this.previewRenderers.clear();
|
|
241
249
|
}
|
|
242
250
|
|
|
243
|
-
private get draft() {
|
|
244
|
-
return this.request.draft;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
private get questions(): readonly AskQuestion[] {
|
|
248
|
-
return this.request.questions;
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
private get isMultiQuestion(): boolean {
|
|
252
|
-
return this.questions.length > 1;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
private get isSubmitTab(): boolean {
|
|
256
|
-
return this.draft.currentIndex >= this.questions.length;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
private currentQuestion(): AskQuestion | undefined {
|
|
260
|
-
return this.questions[this.draft.currentIndex];
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
private allAnswered(): boolean {
|
|
264
|
-
return areAllAnswered(this.questions, this.draft);
|
|
265
|
-
}
|
|
266
|
-
|
|
267
251
|
private renderHeader(width: number): string {
|
|
268
252
|
const contentWidth = width - 2;
|
|
269
253
|
const title = this.theme.bold("Questions");
|
|
270
|
-
const answered = this.draft.answers.filter((answer) => answer !== undefined).length;
|
|
271
|
-
const status = `${answered}/${this.questions.length} answered`;
|
|
254
|
+
const answered = this.view.draft.answers.filter((answer) => answer !== undefined).length;
|
|
255
|
+
const status = `${answered}/${this.view.questions.length} answered`;
|
|
272
256
|
const gap = Math.max(1, contentWidth - visibleWidth(title) - visibleWidth(status));
|
|
273
257
|
|
|
274
258
|
return this.cell(`${title}${" ".repeat(gap)}${this.theme.fg("muted", status)}`, width);
|
|
275
259
|
}
|
|
276
260
|
|
|
277
261
|
private renderFooter(width: number, inputMode: boolean): string {
|
|
278
|
-
const question = this.currentQuestion();
|
|
262
|
+
const question = this.view.currentQuestion();
|
|
279
263
|
|
|
280
264
|
let hints: string;
|
|
281
265
|
|
|
282
266
|
if (inputMode) {
|
|
283
267
|
// Shift+S belongs to the editor while it owns the keys, so the footer must not
|
|
284
268
|
// advertise skip here; Esc leaves the editor and skips from the options.
|
|
285
|
-
hints =
|
|
286
|
-
} else if (this.isSubmitTab) {
|
|
287
|
-
hints = `${this.isMultiQuestion ? "Tab/←→ switch · " : ""}Enter submit · ⇧S skip · Esc close`;
|
|
269
|
+
hints = `Enter submit${this.view.isMultiQuestion ? " · Tab switch" : ""} · Esc back to options`;
|
|
270
|
+
} else if (this.view.isSubmitTab) {
|
|
271
|
+
hints = `${this.view.isMultiQuestion ? "Tab/←→ switch · " : ""}Enter submit · ⇧S skip · Esc close`;
|
|
288
272
|
} else if (question?.multiSelect === true) {
|
|
289
273
|
hints = "↑↓ move · Space/Enter toggle · Tab next · ⇧S skip · Esc close";
|
|
290
274
|
} else {
|
|
291
|
-
hints = `↑↓ select · Enter confirm${this.isMultiQuestion ? " · Tab/←→ switch" : ""} · ⇧S skip · Esc close`;
|
|
275
|
+
hints = `↑↓ select · Enter confirm${this.view.isMultiQuestion ? " · Tab/←→ switch" : ""} · ⇧S skip · Esc close`;
|
|
292
276
|
}
|
|
293
277
|
|
|
294
278
|
return this.cell(this.theme.fg("dim", hints), width);
|
|
@@ -303,13 +287,13 @@ export class QuestionPanelRenderer {
|
|
|
303
287
|
const marks: BodyMarks = {};
|
|
304
288
|
let keep: RenderedBody["keep"];
|
|
305
289
|
|
|
306
|
-
if (this.isSubmitTab) {
|
|
290
|
+
if (this.view.isSubmitTab) {
|
|
307
291
|
lines.push(...this.renderSubmit(contentWidth));
|
|
308
292
|
|
|
309
293
|
return { lines, focusLine: 0, marks };
|
|
310
294
|
}
|
|
311
295
|
|
|
312
|
-
const question = this.currentQuestion();
|
|
296
|
+
const question = this.view.currentQuestion();
|
|
313
297
|
|
|
314
298
|
if (!question) {
|
|
315
299
|
return { lines, focusLine: 0, marks };
|
|
@@ -327,7 +311,10 @@ export class QuestionPanelRenderer {
|
|
|
327
311
|
if (question.displayText) {
|
|
328
312
|
lines.push("");
|
|
329
313
|
|
|
330
|
-
for (const line of this.
|
|
314
|
+
for (const line of this.displayMarkdownFor(
|
|
315
|
+
this.view.draft.currentIndex,
|
|
316
|
+
question.displayText,
|
|
317
|
+
).render(contentWidth)) {
|
|
331
318
|
lines.push(line);
|
|
332
319
|
}
|
|
333
320
|
}
|
|
@@ -362,11 +349,18 @@ export class QuestionPanelRenderer {
|
|
|
362
349
|
marks.editor = { line: lines.length, height: editorLines.length, width: editorWidth };
|
|
363
350
|
|
|
364
351
|
for (const line of editorLines) {
|
|
365
|
-
lines.push(
|
|
352
|
+
lines.push(
|
|
353
|
+
truncateToWidth(`${" ".repeat(EDITOR_INSET)}${line}`, contentWidth, "…", true),
|
|
354
|
+
);
|
|
366
355
|
}
|
|
367
356
|
|
|
368
357
|
lines.push("");
|
|
369
|
-
pushWrapped(
|
|
358
|
+
pushWrapped(
|
|
359
|
+
lines,
|
|
360
|
+
contentWidth,
|
|
361
|
+
" ",
|
|
362
|
+
this.theme.fg("dim", "Enter to submit · Esc to go back"),
|
|
363
|
+
);
|
|
370
364
|
|
|
371
365
|
// The editor owns the keys, so the window follows it instead of the focused option
|
|
372
366
|
// row: the frame and the submit hint stay whole, and only the rows above scroll.
|
|
@@ -398,7 +392,7 @@ export class QuestionPanelRenderer {
|
|
|
398
392
|
inputMode: boolean,
|
|
399
393
|
previewScroll: number,
|
|
400
394
|
): OptionRegion {
|
|
401
|
-
const renderer = this.previewRendererFor(this.draft.currentIndex, question);
|
|
395
|
+
const renderer = this.previewRendererFor(this.view.draft.currentIndex, question);
|
|
402
396
|
|
|
403
397
|
// While the editor is open the focused row is the custom row, which has no preview of
|
|
404
398
|
// its own, and the editor below needs the full width more than a preview does.
|
|
@@ -406,13 +400,13 @@ export class QuestionPanelRenderer {
|
|
|
406
400
|
return this.renderOptionRows(question, contentWidth);
|
|
407
401
|
}
|
|
408
402
|
|
|
409
|
-
const leftWidth = leftColumnWidth(this.questions, contentWidth);
|
|
403
|
+
const leftWidth = leftColumnWidth(this.view.questions, contentWidth);
|
|
410
404
|
const mode = decidePreviewLayout(contentWidth, leftWidth);
|
|
411
405
|
const columns = previewColumnWidths(contentWidth, leftWidth, mode);
|
|
412
406
|
const rows = this.renderOptionRows(question, columns.leftWidth);
|
|
413
407
|
const stackedGap = mode === "stacked" ? STACKED_GAP_ROWS : 0;
|
|
414
|
-
const rowsAboveBlock =
|
|
415
|
-
+ (mode === "stacked" ? rows.lines.length + stackedGap : 0);
|
|
408
|
+
const rowsAboveBlock =
|
|
409
|
+
rowsAboveRegion + (mode === "stacked" ? rows.lines.length + stackedGap : 0);
|
|
416
410
|
const available = maxBodyHeight - rowsAboveBlock;
|
|
417
411
|
|
|
418
412
|
// Too little room left for even a bordered placeholder: the option list keeps the full
|
|
@@ -422,7 +416,7 @@ export class QuestionPanelRenderer {
|
|
|
422
416
|
}
|
|
423
417
|
|
|
424
418
|
const block = renderer.render(
|
|
425
|
-
this.draft.optionIndex,
|
|
419
|
+
this.view.draft.optionIndex,
|
|
426
420
|
columns.rightWidth,
|
|
427
421
|
previewBlockRowBudget(mode, available),
|
|
428
422
|
previewScroll,
|
|
@@ -461,8 +455,8 @@ export class QuestionPanelRenderer {
|
|
|
461
455
|
private renderOptionRows(question: AskQuestion, contentWidth: number): OptionRegion {
|
|
462
456
|
const lines: string[] = [];
|
|
463
457
|
const rows = questionRows(question);
|
|
464
|
-
const focusedIndex = focusedRowIndex(rows, this.draft.optionIndex);
|
|
465
|
-
const answer = this.draft.answers[this.draft.currentIndex];
|
|
458
|
+
const focusedIndex = focusedRowIndex(rows, this.view.draft.optionIndex);
|
|
459
|
+
const answer = this.view.draft.answers[this.view.draft.currentIndex];
|
|
466
460
|
let focusLine = 0;
|
|
467
461
|
|
|
468
462
|
for (const [rowIndex, row] of rows.entries()) {
|
|
@@ -480,7 +474,10 @@ export class QuestionPanelRenderer {
|
|
|
480
474
|
return { lines, focusLine };
|
|
481
475
|
}
|
|
482
476
|
|
|
483
|
-
private previewRendererFor(
|
|
477
|
+
private previewRendererFor(
|
|
478
|
+
questionIndex: number,
|
|
479
|
+
question: AskQuestion,
|
|
480
|
+
): QuestionPreviewRenderer {
|
|
484
481
|
const cached = this.previewRenderers.get(questionIndex);
|
|
485
482
|
|
|
486
483
|
if (cached) {
|
|
@@ -503,7 +500,10 @@ export class QuestionPanelRenderer {
|
|
|
503
500
|
*
|
|
504
501
|
* The strip wraps between tabs, never inside one, so every tab stays one clickable span.
|
|
505
502
|
*/
|
|
506
|
-
private renderTabsBlock(contentWidth: number): {
|
|
503
|
+
private renderTabsBlock(contentWidth: number): {
|
|
504
|
+
lines: string[];
|
|
505
|
+
spans: QuestionPanelLayout["tabs"];
|
|
506
|
+
} {
|
|
507
507
|
const lines: string[] = [];
|
|
508
508
|
const spans: QuestionPanelLayout["tabs"] = [];
|
|
509
509
|
let line = "";
|
|
@@ -542,22 +542,27 @@ export class QuestionPanelRenderer {
|
|
|
542
542
|
return { lines, spans };
|
|
543
543
|
}
|
|
544
544
|
|
|
545
|
-
private tabSegments(): Array<{
|
|
545
|
+
private tabSegments(): Array<{
|
|
546
|
+
text: string;
|
|
547
|
+
style: (text: string) => string;
|
|
548
|
+
target?: TabTarget;
|
|
549
|
+
}> {
|
|
546
550
|
const plain = (text: string) => text;
|
|
547
551
|
const segments: ReturnType<QuestionPanelRenderer["tabSegments"]> = [
|
|
548
552
|
{ text: "←", style: plain, target: { kind: "step", step: -1 } },
|
|
549
553
|
{ text: " ", style: plain },
|
|
550
554
|
];
|
|
551
555
|
|
|
552
|
-
for (const [index, question] of this.questions.entries()) {
|
|
553
|
-
const answered = this.draft.answers[index] !== undefined;
|
|
554
|
-
const active = !this.isSubmitTab && index === this.draft.currentIndex;
|
|
556
|
+
for (const [index, question] of this.view.questions.entries()) {
|
|
557
|
+
const answered = this.view.draft.answers[index] !== undefined;
|
|
558
|
+
const active = !this.view.isSubmitTab && index === this.view.draft.currentIndex;
|
|
555
559
|
|
|
556
560
|
segments.push({
|
|
557
561
|
text: ` ${answered ? "■" : "□"} ${questionTabLabel(question)} `,
|
|
558
|
-
style: (text) =>
|
|
559
|
-
|
|
560
|
-
|
|
562
|
+
style: (text) =>
|
|
563
|
+
active
|
|
564
|
+
? this.theme.bg("selectedBg", this.theme.fg("text", text))
|
|
565
|
+
: this.theme.fg(answered ? "success" : "muted", text),
|
|
561
566
|
target: { kind: "tab", index },
|
|
562
567
|
});
|
|
563
568
|
segments.push({ text: " ", style: plain });
|
|
@@ -566,10 +571,11 @@ export class QuestionPanelRenderer {
|
|
|
566
571
|
segments.push(
|
|
567
572
|
{
|
|
568
573
|
text: " ✓ Submit ",
|
|
569
|
-
style: (text) =>
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
574
|
+
style: (text) =>
|
|
575
|
+
this.view.isSubmitTab
|
|
576
|
+
? this.theme.bg("selectedBg", this.theme.fg("text", text))
|
|
577
|
+
: this.theme.fg(this.view.allAnswered() ? "success" : "dim", text),
|
|
578
|
+
target: { kind: "tab", index: this.view.questions.length },
|
|
573
579
|
},
|
|
574
580
|
{ text: "→", style: plain, target: { kind: "step", step: 1 } },
|
|
575
581
|
);
|
|
@@ -584,9 +590,10 @@ export class QuestionPanelRenderer {
|
|
|
584
590
|
answer: AskQuestionAnswer | undefined,
|
|
585
591
|
contentWidth: number,
|
|
586
592
|
): string[] {
|
|
587
|
-
const
|
|
593
|
+
const cursor = focused ? this.theme.fg("accent", "›") : " ";
|
|
588
594
|
|
|
589
595
|
if (row.kind === "option") {
|
|
596
|
+
const lines: string[] = [];
|
|
590
597
|
const option = question.options?.[row.index];
|
|
591
598
|
|
|
592
599
|
if (!option) {
|
|
@@ -594,11 +601,11 @@ export class QuestionPanelRenderer {
|
|
|
594
601
|
}
|
|
595
602
|
|
|
596
603
|
const chosen = answer?.selectedIndexes.includes(row.index) ?? false;
|
|
597
|
-
const
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
const label =
|
|
604
|
+
const marker =
|
|
605
|
+
question.multiSelect === true
|
|
606
|
+
? this.theme.fg(chosen ? "success" : "dim", chosen ? "[x]" : "[ ]")
|
|
607
|
+
: this.theme.fg(chosen ? "success" : "dim", chosen ? "●" : "○");
|
|
608
|
+
const label = optionLabel(question, row.index);
|
|
602
609
|
const labelColor: ThemeColor = focused || chosen ? "accent" : "text";
|
|
603
610
|
|
|
604
611
|
pushWrapped(
|
|
@@ -609,46 +616,77 @@ export class QuestionPanelRenderer {
|
|
|
609
616
|
);
|
|
610
617
|
|
|
611
618
|
if (option.description) {
|
|
612
|
-
pushWrapped(
|
|
619
|
+
pushWrapped(
|
|
620
|
+
lines,
|
|
621
|
+
contentWidth,
|
|
622
|
+
" ",
|
|
623
|
+
this.theme.fg("muted", option.description),
|
|
624
|
+
);
|
|
613
625
|
}
|
|
614
626
|
|
|
615
627
|
return lines;
|
|
616
628
|
}
|
|
617
629
|
|
|
618
630
|
if (row.kind === "custom") {
|
|
619
|
-
const questionIndex = this.draft.currentIndex;
|
|
620
631
|
// Only a committed answer is shown here. Mirroring the draft would make the row
|
|
621
632
|
// rewrite itself on every keystroke while the editor below shows the same text,
|
|
622
633
|
// and it would follow edits to an answer that was already written.
|
|
623
|
-
const written = this.draft.answers[
|
|
634
|
+
const written = this.view.draft.answers[this.view.draft.currentIndex]?.customText;
|
|
624
635
|
|
|
625
636
|
if (written !== undefined && written.length > 0) {
|
|
637
|
+
const lines: string[] = [];
|
|
638
|
+
|
|
626
639
|
pushWrapped(
|
|
627
640
|
lines,
|
|
628
641
|
contentWidth,
|
|
629
|
-
`${
|
|
630
|
-
this.theme.fg(
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
lines,
|
|
635
|
-
contentWidth,
|
|
636
|
-
`${focused ? this.theme.fg("accent", "›") : " "} ${this.theme.fg("dim", "✎")} `,
|
|
637
|
-
this.theme.fg(focused ? "accent" : "text", "Type something"),
|
|
642
|
+
`${cursor} ${this.theme.fg("dim", "✎")} `,
|
|
643
|
+
this.theme.fg(
|
|
644
|
+
focused ? "accent" : "text",
|
|
645
|
+
summarizeText(written, Math.max(4, contentWidth - 8)),
|
|
646
|
+
),
|
|
638
647
|
);
|
|
639
|
-
|
|
648
|
+
|
|
649
|
+
return lines;
|
|
640
650
|
}
|
|
641
651
|
|
|
642
|
-
return
|
|
652
|
+
return this.renderActionRow(
|
|
653
|
+
cursor,
|
|
654
|
+
"✎",
|
|
655
|
+
"Type something",
|
|
656
|
+
"write your own answer",
|
|
657
|
+
focused,
|
|
658
|
+
contentWidth,
|
|
659
|
+
);
|
|
643
660
|
}
|
|
644
661
|
|
|
662
|
+
return this.renderActionRow(
|
|
663
|
+
cursor,
|
|
664
|
+
"→",
|
|
665
|
+
"Next",
|
|
666
|
+
"confirm the selection",
|
|
667
|
+
focused,
|
|
668
|
+
contentWidth,
|
|
669
|
+
);
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
/** A fixed row: glyph and title, with a muted hint under them. */
|
|
673
|
+
private renderActionRow(
|
|
674
|
+
cursor: string,
|
|
675
|
+
glyph: string,
|
|
676
|
+
title: string,
|
|
677
|
+
hint: string,
|
|
678
|
+
focused: boolean,
|
|
679
|
+
contentWidth: number,
|
|
680
|
+
): string[] {
|
|
681
|
+
const lines: string[] = [];
|
|
682
|
+
|
|
645
683
|
pushWrapped(
|
|
646
684
|
lines,
|
|
647
685
|
contentWidth,
|
|
648
|
-
`${
|
|
649
|
-
this.theme.fg(focused ? "accent" : "text",
|
|
686
|
+
`${cursor} ${this.theme.fg("dim", glyph)} `,
|
|
687
|
+
this.theme.fg(focused ? "accent" : "text", title),
|
|
650
688
|
);
|
|
651
|
-
pushWrapped(lines, contentWidth, " ", this.theme.fg("muted",
|
|
689
|
+
pushWrapped(lines, contentWidth, " ", this.theme.fg("muted", hint));
|
|
652
690
|
|
|
653
691
|
return lines;
|
|
654
692
|
}
|
|
@@ -656,11 +694,16 @@ export class QuestionPanelRenderer {
|
|
|
656
694
|
private renderSubmit(contentWidth: number): string[] {
|
|
657
695
|
const lines: string[] = [];
|
|
658
696
|
|
|
659
|
-
pushWrapped(
|
|
697
|
+
pushWrapped(
|
|
698
|
+
lines,
|
|
699
|
+
contentWidth,
|
|
700
|
+
"",
|
|
701
|
+
this.theme.fg("accent", this.theme.bold("Ready to submit")),
|
|
702
|
+
);
|
|
660
703
|
lines.push("");
|
|
661
704
|
|
|
662
|
-
for (const [index, question] of this.questions.entries()) {
|
|
663
|
-
const answer = this.draft.answers[index];
|
|
705
|
+
for (const [index, question] of this.view.questions.entries()) {
|
|
706
|
+
const answer = this.view.draft.answers[index];
|
|
664
707
|
|
|
665
708
|
pushWrapped(
|
|
666
709
|
lines,
|
|
@@ -683,27 +726,36 @@ export class QuestionPanelRenderer {
|
|
|
683
726
|
|
|
684
727
|
lines.push("");
|
|
685
728
|
|
|
686
|
-
if (this.allAnswered()) {
|
|
729
|
+
if (this.view.allAnswered()) {
|
|
687
730
|
pushWrapped(lines, contentWidth, "", this.theme.fg("success", "Press Enter to submit"));
|
|
688
731
|
} else {
|
|
689
|
-
const missing = this.questions
|
|
690
|
-
.filter((_, index) => this.draft.answers[index] === undefined)
|
|
732
|
+
const missing = this.view.questions
|
|
733
|
+
.filter((_, index) => this.view.draft.answers[index] === undefined)
|
|
691
734
|
.map((question) => questionTabLabel(question))
|
|
692
735
|
.join(", ");
|
|
693
736
|
|
|
694
|
-
pushWrapped(
|
|
737
|
+
pushWrapped(
|
|
738
|
+
lines,
|
|
739
|
+
contentWidth,
|
|
740
|
+
"",
|
|
741
|
+
this.theme.fg("warning", `Unanswered: ${missing}`),
|
|
742
|
+
);
|
|
695
743
|
}
|
|
696
744
|
|
|
697
745
|
return lines;
|
|
698
746
|
}
|
|
699
747
|
|
|
700
|
-
private
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
748
|
+
private displayMarkdownFor(questionIndex: number, text: string): Markdown {
|
|
749
|
+
const cached = this.displayMarkdown.get(questionIndex);
|
|
750
|
+
|
|
751
|
+
if (cached) {
|
|
752
|
+
return cached;
|
|
704
753
|
}
|
|
705
754
|
|
|
706
|
-
|
|
755
|
+
const markdown = new Markdown(text, 0, 0, getMarkdownTheme());
|
|
756
|
+
this.displayMarkdown.set(questionIndex, markdown);
|
|
757
|
+
|
|
758
|
+
return markdown;
|
|
707
759
|
}
|
|
708
760
|
|
|
709
761
|
private frame(text: string): string {
|
|
@@ -796,18 +848,20 @@ function padStartCell(text: string, width: number): string {
|
|
|
796
848
|
return " ".repeat(Math.max(0, width - visibleWidth(clipped))) + clipped;
|
|
797
849
|
}
|
|
798
850
|
|
|
799
|
-
function pushWrapped(
|
|
800
|
-
lines: string[],
|
|
801
|
-
contentWidth: number,
|
|
802
|
-
prefix: string,
|
|
803
|
-
text: string,
|
|
804
|
-
): void {
|
|
851
|
+
function pushWrapped(lines: string[], contentWidth: number, prefix: string, text: string): void {
|
|
805
852
|
const prefixWidth = visibleWidth(prefix);
|
|
806
853
|
const available = Math.max(1, contentWidth - prefixWidth);
|
|
807
854
|
const wrapped = wrapTextWithAnsi(text, available);
|
|
808
855
|
const continuation = " ".repeat(prefixWidth);
|
|
809
856
|
|
|
810
857
|
for (const [index, line] of wrapped.entries()) {
|
|
811
|
-
lines.push(
|
|
858
|
+
lines.push(
|
|
859
|
+
truncateToWidth(
|
|
860
|
+
`${index === 0 ? prefix : continuation}${line}`,
|
|
861
|
+
contentWidth,
|
|
862
|
+
"…",
|
|
863
|
+
true,
|
|
864
|
+
),
|
|
865
|
+
);
|
|
812
866
|
}
|
|
813
867
|
}
|