@juicesharp/rpiv-ask-user-question 2.5.1 → 2.5.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/docs/keyboard.md +7 -0
- package/package.json +2 -2
- package/state/build-questionnaire.ts +7 -0
- package/state/key-router.ts +16 -5
package/docs/keyboard.md
CHANGED
|
@@ -18,6 +18,13 @@ adapts to the size of your terminal.
|
|
|
18
18
|
| `Ctrl+U` | Clear the current custom-answer draft. | `Type something.` input |
|
|
19
19
|
| `Ctrl+]` | Collapse or expand the dialog. Configurable via `collapseKey`. | Everywhere, including while collapsed |
|
|
20
20
|
|
|
21
|
+
The table names the default keys; the dialog actually follows your Pi keybindings.
|
|
22
|
+
Confirm listens to both `tui.select.confirm` and `tui.input.submit`, and a key bound to
|
|
23
|
+
`tui.input.newLine` always inserts a newline even if it also matches confirm. So a
|
|
24
|
+
Slack-style configuration — `enter` folded into `tui.input.newLine`, submit moved to
|
|
25
|
+
`ctrl+enter` — keeps working: `enter` breaks lines, and your submit key confirms
|
|
26
|
+
everywhere `Enter` does.
|
|
27
|
+
|
|
21
28
|
In a multi-select question, `Enter` on a regular row toggles its checkbox exactly like
|
|
22
29
|
`Space` — it does not submit. Committing the question means focusing the `Next` row and
|
|
23
30
|
pressing `Enter`. That is deliberate: it makes `Enter` a zero-cost way to flip boxes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@juicesharp/rpiv-ask-user-question",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.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",
|
|
@@ -93,7 +93,7 @@
|
|
|
93
93
|
}
|
|
94
94
|
},
|
|
95
95
|
"dependencies": {
|
|
96
|
-
"@juicesharp/rpiv-config": "^2.5.
|
|
96
|
+
"@juicesharp/rpiv-config": "^2.5.2",
|
|
97
97
|
"typebox": "^1.1.24"
|
|
98
98
|
}
|
|
99
99
|
}
|
|
@@ -130,6 +130,13 @@ class QuestionnaireBuilder {
|
|
|
130
130
|
const textEditorTheme = editorTheme(this.theme);
|
|
131
131
|
this.notesInput = new Editor(this.tui, textEditorTheme);
|
|
132
132
|
this.inlineInput = new Editor(this.tui, textEditorTheme);
|
|
133
|
+
// The key router owns confirm/submit semantics; keys reaching these headless
|
|
134
|
+
// editors are text-editing only. Without this, a `tui.input.submit` match inside
|
|
135
|
+
// Editor.handleInput would run submitValue(), which resets the buffer and
|
|
136
|
+
// silently destroys the draft — no onSubmit is wired here, so the text is
|
|
137
|
+
// unrecoverable (#156).
|
|
138
|
+
this.notesInput.disableSubmit = true;
|
|
139
|
+
this.inlineInput.disableSubmit = true;
|
|
133
140
|
}
|
|
134
141
|
|
|
135
142
|
build(): QuestionnaireBuilt {
|
package/state/key-router.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type { QuestionnaireRuntime, QuestionnaireState } from "./state.js";
|
|
|
6
6
|
const KEYBIND_UP = "tui.select.up";
|
|
7
7
|
const KEYBIND_DOWN = "tui.select.down";
|
|
8
8
|
const KEYBIND_CONFIRM = "tui.select.confirm";
|
|
9
|
+
const KEYBIND_SUBMIT = "tui.input.submit";
|
|
9
10
|
const KEYBIND_CANCEL = "tui.select.cancel";
|
|
10
11
|
const KEYBIND_NEW_LINE = "tui.input.newLine";
|
|
11
12
|
const KEYBIND_EDITOR_UP = "tui.editor.cursorUp";
|
|
@@ -39,6 +40,16 @@ export interface QuestionnaireKeybindings {
|
|
|
39
40
|
matches(data: string, name: string): boolean;
|
|
40
41
|
}
|
|
41
42
|
|
|
43
|
+
// Confirm has two semantic sources: `tui.select.confirm` (the select-list default)
|
|
44
|
+
// and `tui.input.submit` (the user's "send" key). A Slack-style configuration folds
|
|
45
|
+
// `enter` into `tui.input.newLine` and moves submit elsewhere (e.g. `ctrl+enter`);
|
|
46
|
+
// the newline checks below stay first, so without the submit source every confirm
|
|
47
|
+
// branch would be shadowed by the collision and no key could confirm (#156). With
|
|
48
|
+
// pi defaults both names resolve to `enter`, so matching either is equivalent.
|
|
49
|
+
function isConfirm(kb: QuestionnaireKeybindings, data: string): boolean {
|
|
50
|
+
return kb.matches(data, KEYBIND_CONFIRM) || kb.matches(data, KEYBIND_SUBMIT);
|
|
51
|
+
}
|
|
52
|
+
|
|
42
53
|
export function wrapTab(index: number, total: number): number {
|
|
43
54
|
if (total <= 0) return 0;
|
|
44
55
|
return ((index % total) + total) % total;
|
|
@@ -183,7 +194,7 @@ export function routeKey(data: string, state: QuestionnaireState, runtime: Quest
|
|
|
183
194
|
if (state.notesVisible) {
|
|
184
195
|
if (kb.matches(data, KEYBIND_CANCEL)) return { kind: "notes_exit" };
|
|
185
196
|
if (kb.matches(data, KEYBIND_NEW_LINE)) return { kind: "notes_forward", data };
|
|
186
|
-
if (kb
|
|
197
|
+
if (isConfirm(kb, data)) return { kind: "notes_exit" };
|
|
187
198
|
return { kind: "notes_forward", data };
|
|
188
199
|
}
|
|
189
200
|
|
|
@@ -191,7 +202,7 @@ export function routeKey(data: string, state: QuestionnaireState, runtime: Quest
|
|
|
191
202
|
// Newline takes precedence over confirmation if a user configuration binds
|
|
192
203
|
// the same physical key to both semantic actions.
|
|
193
204
|
if (kb.matches(data, KEYBIND_NEW_LINE)) return { kind: "ignore" };
|
|
194
|
-
if (kb
|
|
205
|
+
if (isConfirm(kb, data)) {
|
|
195
206
|
const answer = buildSingleSelectAnswer(state, runtime);
|
|
196
207
|
if (!answer) return { kind: "ignore" };
|
|
197
208
|
return { kind: "confirm", answer, autoAdvanceTab: computeAutoAdvanceTab(state, runtime) };
|
|
@@ -219,7 +230,7 @@ export function routeKey(data: string, state: QuestionnaireState, runtime: Quest
|
|
|
219
230
|
const next = wrapTab(state.submitChoiceIndex + delta, 2);
|
|
220
231
|
return { kind: "submit_nav", nextIndex: (next === 1 ? 1 : 0) as 0 | 1 };
|
|
221
232
|
}
|
|
222
|
-
if (kb
|
|
233
|
+
if (isConfirm(kb, data)) {
|
|
223
234
|
// D1 (revised): Submit always submits; Cancel always cancels. The warning header
|
|
224
235
|
// is informational only — `allAnswered(state)` no longer gates submission. Partial
|
|
225
236
|
// answers flow through `orderedAnswers()` in the host.
|
|
@@ -265,7 +276,7 @@ export function routeKey(data: string, state: QuestionnaireState, runtime: Quest
|
|
|
265
276
|
if (focusedMeta?.activatesInputMode) return { kind: "ignore" };
|
|
266
277
|
return { kind: "toggle", index: state.optionIndex };
|
|
267
278
|
}
|
|
268
|
-
if (kb
|
|
279
|
+
if (isConfirm(kb, data)) {
|
|
269
280
|
// Enter on the "Type something." row is handled by the inputMode block above
|
|
270
281
|
// (→ confirm kind:"custom"). Defensive: never enter the toggle/multi_confirm
|
|
271
282
|
// path for an inputMode-activating row.
|
|
@@ -289,7 +300,7 @@ export function routeKey(data: string, state: QuestionnaireState, runtime: Quest
|
|
|
289
300
|
return { kind: "ignore" };
|
|
290
301
|
}
|
|
291
302
|
|
|
292
|
-
if (kb
|
|
303
|
+
if (isConfirm(kb, data)) {
|
|
293
304
|
const answer = buildSingleSelectAnswer(state, runtime);
|
|
294
305
|
if (!answer) return { kind: "ignore" };
|
|
295
306
|
return { kind: "confirm", answer, autoAdvanceTab: computeAutoAdvanceTab(state, runtime) };
|