@juicesharp/rpiv-ask-user-question 1.9.0 → 1.9.1
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/README.md
CHANGED
|
@@ -23,6 +23,7 @@ Let the model ask you structured clarifying questions instead of guessing. `rpiv
|
|
|
23
23
|
- **Multi-select questions** - checkboxes with `Space` to toggle, Enter-as-toggle on rows, a `Next` sentinel to advance, and toggles persisted across tab switches.
|
|
24
24
|
- **Submit tab** - review every answer before submitting; warns about unanswered questions and offers a Submit picker.
|
|
25
25
|
- **Chat row on every tab** - redirect the conversation without leaving the dialog.
|
|
26
|
+
- **Terminal-row-aware overflow scroll** - when the dialog is taller than the terminal, the body scrolls between a sticky heading and sticky hints/border; overflow indicators (↑ / ↓ / ↕) show what's clipped.
|
|
26
27
|
- **"Other" free-text fallback** - type a custom answer when no option fits.
|
|
27
28
|
- **Localized UI** - sentinel rows, hints, submit/cancel labels, review pane, and notes affordance display in the user's chosen language via `@juicesharp/rpiv-i18n`. Ships Deutsch / English / Español / Français / Português (PT) / Português (BR) / Русский / Українська; switch with `/languages` or `pi --locale <code>`. LLM-facing copy (tool description, schemas, errors) stays English by design.
|
|
28
29
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@juicesharp/rpiv-ask-user-question",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.1",
|
|
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",
|
|
@@ -82,6 +82,6 @@
|
|
|
82
82
|
}
|
|
83
83
|
},
|
|
84
84
|
"dependencies": {
|
|
85
|
-
"@juicesharp/rpiv-config": "^1.9.
|
|
85
|
+
"@juicesharp/rpiv-config": "^1.9.1"
|
|
86
86
|
}
|
|
87
87
|
}
|
|
@@ -23,6 +23,7 @@ export interface OptionListViewProps {
|
|
|
23
23
|
selectedIndex: number;
|
|
24
24
|
focused: boolean;
|
|
25
25
|
inputBuffer: string;
|
|
26
|
+
inputCursorOffset?: number;
|
|
26
27
|
/** Optional previously-confirmed indicator. Omit when no marker should be drawn. */
|
|
27
28
|
confirmed?: { index: number; labelOverride?: string };
|
|
28
29
|
}
|
|
@@ -51,6 +52,7 @@ export class OptionListView implements StatefulView<OptionListViewProps> {
|
|
|
51
52
|
this.select.setFocused(props.focused);
|
|
52
53
|
this.select.setConfirmedIndex(props.confirmed?.index, props.confirmed?.labelOverride);
|
|
53
54
|
this.select.setInputBuffer(props.inputBuffer);
|
|
55
|
+
this.select.setInputCursorOffset(props.inputCursorOffset);
|
|
54
56
|
}
|
|
55
57
|
|
|
56
58
|
handleInput(_data: string): void {}
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import type { Component } from "@earendil-works/pi-tui";
|
|
2
|
-
import { visibleWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
|
|
2
|
+
import { CURSOR_MARKER, visibleWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
|
|
3
|
+
|
|
4
|
+
// Grapheme-aware extraction at the cursor: pi-tui's Input advances `cursor` by
|
|
5
|
+
// grapheme-cluster code-unit length, so the cursor can land between code units of
|
|
6
|
+
// one cluster (emoji, ZWJ, combining marks). Single-code-unit slicing would split
|
|
7
|
+
// the cluster across the SGR 7/27 boundary.
|
|
8
|
+
const graphemeSegmenter = new Intl.Segmenter(undefined, { granularity: "grapheme" });
|
|
3
9
|
|
|
4
10
|
/**
|
|
5
11
|
* Row-intent discriminated union. `kind` is the single discriminator —
|
|
@@ -47,7 +53,6 @@ export class WrappingSelect implements Component {
|
|
|
47
53
|
private static readonly ACTIVE_POINTER = "❯ ";
|
|
48
54
|
private static readonly INACTIVE_POINTER = " ";
|
|
49
55
|
private static readonly NUMBER_SEPARATOR = ". ";
|
|
50
|
-
private static readonly INPUT_CURSOR = "▌";
|
|
51
56
|
private static readonly CONFIRMED_MARK = " ✔";
|
|
52
57
|
private static readonly MIN_CONTENT_WIDTH = 1;
|
|
53
58
|
|
|
@@ -60,6 +65,7 @@ export class WrappingSelect implements Component {
|
|
|
60
65
|
private selectedIndex = 0;
|
|
61
66
|
private focused = true;
|
|
62
67
|
private inputBuffer = "";
|
|
68
|
+
private inputCursorOffset: number | undefined = undefined;
|
|
63
69
|
/**
|
|
64
70
|
* Index of the row that was previously confirmed for this list (e.g. the user's prior
|
|
65
71
|
* answer when re-entering a multi-question tab). Renders `<label> ✔` in the active-row
|
|
@@ -125,6 +131,11 @@ export class WrappingSelect implements Component {
|
|
|
125
131
|
this.inputBuffer = text;
|
|
126
132
|
}
|
|
127
133
|
|
|
134
|
+
/** Set the cursor offset for the inline input row. `undefined` → end-of-buffer fallback. */
|
|
135
|
+
setInputCursorOffset(offset: number | undefined): void {
|
|
136
|
+
this.inputCursorOffset = offset;
|
|
137
|
+
}
|
|
138
|
+
|
|
128
139
|
/** Intentionally empty — input is routed at the container level. */
|
|
129
140
|
handleInput(_data: string): void {}
|
|
130
141
|
|
|
@@ -248,14 +259,43 @@ export class WrappingSelect implements Component {
|
|
|
248
259
|
* so long input doesn't run off the right edge or trip the parent renderer's
|
|
249
260
|
* width invariant. Mirrors `renderLabelBlock`'s contract: first line carries
|
|
250
261
|
* `rowPrefix`, continuation lines carry `continuationPrefix` (spaces), and every
|
|
251
|
-
* emitted line passes through `theme.selectedText`.
|
|
252
|
-
*
|
|
253
|
-
*
|
|
254
|
-
*
|
|
255
|
-
*
|
|
262
|
+
* emitted line passes through `theme.selectedText`.
|
|
263
|
+
*
|
|
264
|
+
* Cursor visualization follows the standard TUI input-widget pattern (ECMA-48
|
|
265
|
+
* SGR 7 reverse-video on the cell *at* the cursor, not an inserted glyph) —
|
|
266
|
+
* same approach used by pi-tui Input.render (input.js:411-418), ink-text-input,
|
|
267
|
+
* terkelg/prompts, ratatui's user-input example, etc. Split: `before | at | after`
|
|
268
|
+
* where `at` is the single character under the cursor (or U+00A0 NBSP at end-of-
|
|
269
|
+
* buffer) wrapped in `\x1b[7m…\x1b[27m`. No characters shift; the column under
|
|
270
|
+
* the cursor inverts.
|
|
271
|
+
*
|
|
272
|
+
* pi-tui's zero-width `CURSOR_MARKER` (APC sentinel) is emitted immediately
|
|
273
|
+
* before the `at` cell so the TUI framebuffer can position the hardware
|
|
274
|
+
* terminal cursor at that column (visible iff pi's `showHardwareCursor`
|
|
275
|
+
* setting is on — `pi-coding-agent/main.js:303`). `visibleWidth` strips the
|
|
276
|
+
* marker as zero-width (utils.js:187-203), so wrap math is preserved.
|
|
277
|
+
*
|
|
278
|
+
* NBSP at end-of-buffer (rather than literal space): `wrapTextWithAnsi`
|
|
279
|
+
* tokenizes on whitespace, so a literal space inside the reverse-video escape
|
|
280
|
+
* pair would cause `wrapTextWithAnsi` to break the line at the cursor. NBSP
|
|
281
|
+
* preserves the visible width-1 contribution without registering as a wrap
|
|
282
|
+
* break — the conventional workaround documented across ANSI-aware string
|
|
283
|
+
* wrappers.
|
|
256
284
|
*/
|
|
257
285
|
private renderInlineInputRow(rowPrefix: string, continuationPrefix: string, contentWidth: number): string[] {
|
|
258
|
-
const
|
|
286
|
+
const buffer = this.inputBuffer;
|
|
287
|
+
const requested = this.inputCursorOffset;
|
|
288
|
+
const offset =
|
|
289
|
+
requested !== undefined && requested >= 0 && requested <= buffer.length ? requested : buffer.length;
|
|
290
|
+
const before = buffer.slice(0, offset);
|
|
291
|
+
const [firstGrapheme] = graphemeSegmenter.segment(buffer.slice(offset));
|
|
292
|
+
const rawAt = firstGrapheme ? firstGrapheme.segment : "";
|
|
293
|
+
// Whitespace at cursor (including end-of-buffer fallback) tokenizes as a wrap
|
|
294
|
+
// break inside `wrapTextWithAnsi`, splitting the line at the cursor. Substitute
|
|
295
|
+
// U+00A0 (NBSP): visually identical to a space, wrap-safe.
|
|
296
|
+
const atCursor = rawAt === "" || rawAt === " " ? " " : rawAt;
|
|
297
|
+
const after = buffer.slice(offset + rawAt.length);
|
|
298
|
+
const raw = `${before}${CURSOR_MARKER}\x1b[7m${atCursor}\x1b[27m${after}`;
|
|
259
299
|
const wrapped = wrapTextWithAnsi(raw, contentWidth);
|
|
260
300
|
return wrapped.map((segment, index) => {
|
|
261
301
|
const prefix = index === 0 ? rowPrefix : continuationPrefix;
|
package/view/props-adapter.ts
CHANGED
|
@@ -13,6 +13,20 @@ interface Invalidatable {
|
|
|
13
13
|
invalidate(): void;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Reads pi-tui Input's private `cursor` field via type escape with full runtime validation.
|
|
18
|
+
* Returns `undefined` on any failure → graceful degradation to end-of-buffer cursor.
|
|
19
|
+
* Follow-up: replace with Input.getCursorOffset() when pi-tui exposes a public API.
|
|
20
|
+
*/
|
|
21
|
+
function getInputCursorOffset(input: Input): number | undefined {
|
|
22
|
+
const raw = (input as unknown as { cursor?: unknown }).cursor;
|
|
23
|
+
if (typeof raw !== "number") return undefined;
|
|
24
|
+
if (!Number.isSafeInteger(raw)) return undefined;
|
|
25
|
+
const value = input.getValue();
|
|
26
|
+
if (raw < 0 || raw > value.length) return undefined;
|
|
27
|
+
return raw;
|
|
28
|
+
}
|
|
29
|
+
|
|
16
30
|
export interface QuestionnairePropsAdapterConfig {
|
|
17
31
|
tui: { requestRender(): void };
|
|
18
32
|
questions: readonly QuestionData[];
|
|
@@ -71,6 +85,7 @@ export class QuestionnairePropsAdapter {
|
|
|
71
85
|
totalQuestions,
|
|
72
86
|
activeView,
|
|
73
87
|
inputBuffer: this.inlineInput.getValue(),
|
|
88
|
+
inputCursorOffset: getInputCursorOffset(this.inlineInput),
|
|
74
89
|
activePreviewPane,
|
|
75
90
|
};
|
|
76
91
|
|