@juicesharp/rpiv-ask-user-question 2.1.0 → 2.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.
@@ -1,5 +1,5 @@
1
1
  import { DynamicBorder, type Theme } from "@earendil-works/pi-coding-agent";
2
- import { type Component, Container, type Input, Spacer } from "@earendil-works/pi-tui";
2
+ import { type Component, Container, type Editor, Spacer } from "@earendil-works/pi-tui";
3
3
  import type { QuestionnaireState } from "../state/state.js";
4
4
  import type { QuestionData } from "../tool/types.js";
5
5
  import type { PreviewPaneProps } from "./components/preview/preview-pane.js";
@@ -10,6 +10,8 @@ import { QuestionTabStrategy, SubmitTabStrategy, type TabContentStrategy } from
10
10
 
11
11
  export const HINT_PART_ENTER = "Enter to select";
12
12
  export const HINT_PART_NAV = "↑/↓ to navigate";
13
+ export const HINT_PART_NEW_LINE = "Shift+Enter for newline";
14
+ export const HINT_PART_CLEAR = "Ctrl+U to clear";
13
15
  export const HINT_PART_TOGGLE = "Space to toggle";
14
16
  export const HINT_PART_NOTES = "n to add notes";
15
17
  export const HINT_PART_TAB = "Tab to switch questions";
@@ -54,7 +56,7 @@ export interface DialogConfig {
54
56
  theme: Theme;
55
57
  questions: readonly QuestionData[];
56
58
  tabBar: TabBar | undefined;
57
- notesInput: Input;
59
+ notesInput: Editor;
58
60
  isMulti: boolean;
59
61
  tabsByIndex: ReadonlyArray<TabComponents>;
60
62
  /** Optional so single-question mode and non-submit tests can omit it; SubmitTabStrategy falls back to Spacer rows. */
@@ -1,4 +1,4 @@
1
- import type { Input } from "@earendil-works/pi-tui";
1
+ import type { Editor } from "@earendil-works/pi-tui";
2
2
  import type { BindingContext, PerTabBindingContext } from "../state/selectors/contract.js";
3
3
  import { selectActivePreviewPaneIndex } from "../state/selectors/derivations.js";
4
4
  import { selectActiveView } from "../state/selectors/focus.js";
@@ -13,18 +13,12 @@ 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;
16
+ function getInputCursorOffset(input: Editor): number {
17
+ const lines = input.getLines();
18
+ const cursor = input.getCursor();
19
+ let offset = cursor.col;
20
+ for (let i = 0; i < cursor.line; i++) offset += (lines[i]?.length ?? 0) + 1;
21
+ return offset;
28
22
  }
29
23
 
30
24
  export interface QuestionnairePropsAdapterConfig {
@@ -32,12 +26,12 @@ export interface QuestionnairePropsAdapterConfig {
32
26
  questions: readonly QuestionData[];
33
27
  itemsByTab: ReadonlyArray<readonly WrappingSelectItem[]>;
34
28
  tabsByIndex: ReadonlyArray<TabComponents>;
35
- inlineInput: Input;
29
+ inlineInput: Editor;
36
30
  globalBindings: ReadonlyArray<BoundGlobalBinding>;
37
31
  perTabBindings: ReadonlyArray<BoundPerTabBinding>;
38
32
  /**
39
33
  * Renderables not reached by the binding registries (e.g. the notes
40
- * `Input`, which is typed into directly and has no props). Walked by
34
+ * `Editor`, which is typed into directly and has no props). Walked by
41
35
  * `invalidate()` after the binding-driven components.
42
36
  */
43
37
  extraInvalidatables?: ReadonlyArray<Invalidatable>;
@@ -57,7 +51,7 @@ export class QuestionnairePropsAdapter {
57
51
  private readonly questions: readonly QuestionData[];
58
52
  private readonly itemsByTab: ReadonlyArray<readonly WrappingSelectItem[]>;
59
53
  private readonly tabsByIndex: ReadonlyArray<TabComponents>;
60
- private readonly inlineInput: Input;
54
+ private readonly inlineInput: Editor;
61
55
  private readonly globalBindings: ReadonlyArray<BoundGlobalBinding>;
62
56
  private readonly perTabBindings: ReadonlyArray<BoundPerTabBinding>;
63
57
  private readonly extraInvalidatables: ReadonlyArray<Invalidatable>;
@@ -84,7 +78,7 @@ export class QuestionnairePropsAdapter {
84
78
  itemsByTab: this.itemsByTab,
85
79
  totalQuestions,
86
80
  activeView,
87
- inputBuffer: this.inlineInput.getValue(),
81
+ inputBuffer: this.inlineInput.getText(),
88
82
  inputCursorOffset: getInputCursorOffset(this.inlineInput),
89
83
  activePreviewPane,
90
84
  };
@@ -1,5 +1,5 @@
1
1
  import type { Theme } from "@earendil-works/pi-coding-agent";
2
- import { type Component, Container, type Input, Spacer, Text, truncateToWidth } from "@earendil-works/pi-tui";
2
+ import { type Component, Container, type Editor, Spacer, Text, truncateToWidth } from "@earendil-works/pi-tui";
3
3
  import { t } from "../state/i18n-bridge.js";
4
4
  import { formatAnswerScalar } from "../tool/format-answer.js";
5
5
  import type { QuestionData } from "../tool/types.js";
@@ -7,9 +7,11 @@ import type { PreviewPane, PreviewPaneProps } from "./components/preview/preview
7
7
  import {
8
8
  type DialogState,
9
9
  HINT_PART_CANCEL,
10
+ HINT_PART_CLEAR,
10
11
  HINT_PART_COLLAPSE,
11
12
  HINT_PART_ENTER,
12
13
  HINT_PART_NAV,
14
+ HINT_PART_NEW_LINE,
13
15
  HINT_PART_NOTES,
14
16
  HINT_PART_TAB,
15
17
  HINT_PART_TOGGLE,
@@ -81,7 +83,7 @@ export interface QuestionTabStrategyConfig {
81
83
  questions: readonly QuestionData[];
82
84
  getPreviewPane: () => StatefulView<PreviewPaneProps>;
83
85
  tabsByIndex: ReadonlyArray<TabComponents>;
84
- notesInput: Input;
86
+ notesInput: Editor;
85
87
  isMulti: boolean;
86
88
  getCurrentBodyHeight: (width: number) => number;
87
89
  }
@@ -227,24 +229,21 @@ export class SubmitTabStrategy implements TabContentStrategy {
227
229
  /**
228
230
  * Build the controls hint line. Order:
229
231
  * Enter · ↑/↓ [· Space toggle] [· n notes] [· Tab switch] · Esc · Ctrl+] collapse
232
+ * [· Shift+Enter newline] [· Ctrl+U clear]
230
233
  *
231
- * `NOTES` is now part of the resting (notes-closed) core — it renders on every
232
- * question tab and drops when `state.notesVisible` flips the editor open OR while
233
- * `state.inputMode` has the "Type something." row capturing text (`n` would insert
234
- * a literal character there, so advertising it would lie). The collapse affordance
235
- * is appended last so the resting core stays a contiguous substring even when the
236
- * trailing part is clipped by `OneLineClippedText` on terminals < ~95 cols. This
237
- * is the trade we picked over wrapping (which would inflate `footerRowCount` and
238
- * desync the height math in `DialogView.render`).
234
+ * `NOTES` is part of the resting (notes-closed) core — it drops while the notes
235
+ * editor or custom-answer input has the keyboard. Ctrl+G is Pi's global external-
236
+ * editor shortcut and needs no local hint; the context-specific clear shortcut is
237
+ * appended at the far right while input mode is active.
239
238
  */
240
239
  export function buildHintText(question: QuestionData | undefined, isMulti: boolean, state: DialogState): string {
241
240
  const parts: string[] = [t("hint.enter", HINT_PART_ENTER), t("hint.navigate", HINT_PART_NAV)];
242
241
  if (question?.multiSelect === true) parts.push(t("hint.toggle", HINT_PART_TOGGLE));
243
- if (question && !state.notesVisible && !state.inputMode) {
244
- parts.push(t("hint.notes", HINT_PART_NOTES));
245
- }
242
+ if (question && !state.notesVisible && !state.inputMode) parts.push(t("hint.notes", HINT_PART_NOTES));
246
243
  if (isMulti) parts.push(t("hint.tab", HINT_PART_TAB));
247
244
  parts.push(t("hint.cancel", HINT_PART_CANCEL));
248
245
  parts.push(t("hint.collapse", HINT_PART_COLLAPSE));
246
+ if (state.notesVisible || state.inputMode) parts.push(t("hint.newline", HINT_PART_NEW_LINE));
247
+ if (state.inputMode) parts.push(t("hint.clear", HINT_PART_CLEAR));
249
248
  return parts.join(" · ");
250
249
  }