ink-prompt 0.1.6 → 0.1.7
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,37 +1,110 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
export interface MultilineInputProps {
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Controlled text value. When provided, the component becomes controlled
|
|
5
|
+
* and the value is managed externally.
|
|
6
|
+
*/
|
|
4
7
|
value?: string;
|
|
5
|
-
/**
|
|
8
|
+
/**
|
|
9
|
+
* Called when the text content changes due to user input. Receives the
|
|
10
|
+
* new text value as a parameter.
|
|
11
|
+
*/
|
|
6
12
|
onChange?: (value: string) => void;
|
|
7
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* Called when the user submits the input (typically by pressing Enter
|
|
15
|
+
* without a backslash at the end). Receives the final text value.
|
|
16
|
+
*/
|
|
8
17
|
onSubmit?: (value: string) => void;
|
|
9
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* Placeholder text displayed when the input is empty and the cursor
|
|
20
|
+
* is not shown.
|
|
21
|
+
*/
|
|
10
22
|
placeholder?: string;
|
|
11
|
-
/**
|
|
23
|
+
/**
|
|
24
|
+
* Whether to display the cursor. Defaults to true.
|
|
25
|
+
*/
|
|
12
26
|
showCursor?: boolean;
|
|
13
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* Terminal width for word wrapping. If not provided, uses the terminal's
|
|
29
|
+
* current width with resize support.
|
|
30
|
+
*/
|
|
14
31
|
width?: number;
|
|
15
|
-
/**
|
|
32
|
+
/**
|
|
33
|
+
* Whether the input is active and focused, allowing keyboard input.
|
|
34
|
+
* Defaults to true.
|
|
35
|
+
*/
|
|
16
36
|
isActive?: boolean;
|
|
17
|
-
/**
|
|
37
|
+
/**
|
|
38
|
+
* Called whenever the cursor position changes. Receives the flat
|
|
39
|
+
* character offset as a parameter.
|
|
40
|
+
*/
|
|
18
41
|
onCursorChange?: (offset: number) => void;
|
|
19
|
-
/**
|
|
42
|
+
/**
|
|
43
|
+
* Optional external cursor position override. When set, forces the
|
|
44
|
+
* cursor to the specified flat character offset.
|
|
45
|
+
*/
|
|
20
46
|
cursorOverride?: number;
|
|
47
|
+
/**
|
|
48
|
+
* Called when an arrow key is pressed but cursor is at a boundary.
|
|
49
|
+
* - 'up': cursor is on the first/topmost line
|
|
50
|
+
* - 'down': cursor is on the last/bottommost line
|
|
51
|
+
* - 'left': cursor is at position 0 (start of text)
|
|
52
|
+
* - 'right': cursor is at end of text (after last character)
|
|
53
|
+
*/
|
|
54
|
+
onBoundaryArrow?: (direction: 'up' | 'down' | 'left' | 'right') => void;
|
|
21
55
|
}
|
|
22
56
|
/**
|
|
23
57
|
* Props for the core component (without Ink-specific hooks)
|
|
24
58
|
* This allows testing the rendering logic separately.
|
|
25
59
|
*/
|
|
26
60
|
export interface MultilineInputCoreProps {
|
|
61
|
+
/**
|
|
62
|
+
* Controlled text value. When provided, the component becomes controlled
|
|
63
|
+
* and the text is managed externally.
|
|
64
|
+
*/
|
|
27
65
|
value?: string;
|
|
66
|
+
/**
|
|
67
|
+
* Called when the text content changes. Receives the new text value
|
|
68
|
+
* as a parameter.
|
|
69
|
+
*/
|
|
28
70
|
onChange?: (value: string) => void;
|
|
71
|
+
/**
|
|
72
|
+
* Called when the user submits the input (typically by pressing Enter
|
|
73
|
+
* without a backslash at the end).
|
|
74
|
+
*/
|
|
29
75
|
onSubmit?: (value: string) => void;
|
|
76
|
+
/**
|
|
77
|
+
* Placeholder text displayed when the input is empty and the cursor
|
|
78
|
+
* is not shown.
|
|
79
|
+
*/
|
|
30
80
|
placeholder?: string;
|
|
81
|
+
/**
|
|
82
|
+
* Whether to display the cursor. Defaults to true.
|
|
83
|
+
*/
|
|
31
84
|
showCursor?: boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Terminal width for word wrapping. If not provided, uses the terminal's
|
|
87
|
+
* current width.
|
|
88
|
+
*/
|
|
32
89
|
width?: number;
|
|
90
|
+
/**
|
|
91
|
+
* Called whenever the cursor position changes. Receives the flat
|
|
92
|
+
* character offset as a parameter.
|
|
93
|
+
*/
|
|
33
94
|
onCursorChange?: (offset: number) => void;
|
|
95
|
+
/**
|
|
96
|
+
* Optional external cursor position override. When set, forces the
|
|
97
|
+
* cursor to the specified flat character offset.
|
|
98
|
+
*/
|
|
34
99
|
cursorOverride?: number;
|
|
100
|
+
/**
|
|
101
|
+
* Called when an arrow key is pressed but cursor is at a boundary.
|
|
102
|
+
* - 'up': cursor is on the first/topmost line
|
|
103
|
+
* - 'down': cursor is on the last/bottommost line
|
|
104
|
+
* - 'left': cursor is at position 0 (start of text)
|
|
105
|
+
* - 'right': cursor is at end of text (after last character)
|
|
106
|
+
*/
|
|
107
|
+
onBoundaryArrow?: (direction: 'up' | 'down' | 'left' | 'right') => void;
|
|
35
108
|
}
|
|
36
109
|
/**
|
|
37
110
|
* Core rendering component that can be tested without Ink runtime.
|
|
@@ -66,7 +66,7 @@ export const MultilineInputCore = ({ value, onChange, placeholder, showCursor =
|
|
|
66
66
|
* Full MultilineInput with Ink keyboard handling.
|
|
67
67
|
* This component uses Ink-specific hooks and must be rendered in an Ink context.
|
|
68
68
|
*/
|
|
69
|
-
export const MultilineInput = ({ value, onChange, onSubmit, placeholder, showCursor = true, width, isActive = true, onCursorChange, cursorOverride, }) => {
|
|
69
|
+
export const MultilineInput = ({ value, onChange, onSubmit, placeholder, showCursor = true, width, isActive = true, onCursorChange, cursorOverride, onBoundaryArrow, }) => {
|
|
70
70
|
// Get terminal width from Ink (with resize support) if not provided
|
|
71
71
|
const terminalWidth = useTerminalWidth(width);
|
|
72
72
|
// Track raw input for detecting Home/End keys
|
|
@@ -140,11 +140,12 @@ export const MultilineInput = ({ value, onChange, onSubmit, placeholder, showCur
|
|
|
140
140
|
redo: textInput.redo,
|
|
141
141
|
setText: textInput.setText,
|
|
142
142
|
submit: handleSubmit,
|
|
143
|
+
onBoundaryArrow,
|
|
143
144
|
};
|
|
144
145
|
// Handle keyboard input
|
|
145
146
|
useInput((input, key) => {
|
|
146
147
|
log(`[USEINPUT] input="${input.replace(/[\x00-\x1F\x7F-\uFFFF]/g, c => `\\x${c.charCodeAt(0).toString(16)}`)}" key=${JSON.stringify(key)} rawLen=${lastRawInput.current?.length || 0}`);
|
|
147
|
-
handleKey(key, input, buffer, actions, textInput.cursor, lastRawInput.current);
|
|
148
|
+
handleKey(key, input, buffer, actions, textInput.cursor, lastRawInput.current, terminalWidth);
|
|
148
149
|
}, { isActive });
|
|
149
150
|
// Show placeholder if empty and no cursor shown
|
|
150
151
|
const isEmpty = textInput.value === '';
|