ink-prompt 0.3.0 → 0.3.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.
|
@@ -9,7 +9,12 @@ import { TextRenderer } from './TextRenderer.js';
|
|
|
9
9
|
import { useClipboardPaste } from './useClipboardPaste.js';
|
|
10
10
|
import { log } from '../../utils/logger.js';
|
|
11
11
|
export const MultilineInputCore = ({ value, onChange, placeholder, showCursor = true, width = 80, onCursorChange, cursorOverride, undoDebounceMs, pasteThreshold, formatPastePlaceholder, images, onImagesChange, maxHeight, }) => {
|
|
12
|
-
const textInput = useTextInput({
|
|
12
|
+
const textInput = useTextInput({
|
|
13
|
+
initialValue: value ?? '',
|
|
14
|
+
undoDebounceMs,
|
|
15
|
+
pasteThreshold,
|
|
16
|
+
formatPastePlaceholder,
|
|
17
|
+
});
|
|
13
18
|
const isSyncingFromProps = useRef(false);
|
|
14
19
|
useEffect(() => {
|
|
15
20
|
if (cursorOverride !== undefined) {
|
|
@@ -64,14 +69,20 @@ export const MultilineInputCore = ({ value, onChange, placeholder, showCursor =
|
|
|
64
69
|
const effectiveMaxHeight = maxHeight ?? defaultMaxHeight;
|
|
65
70
|
return (_jsx(TextRenderer, { buffer: textInput.buffer, cursor: textInput.cursor, width: width, showCursor: showCursor, blockState: textInput.blockState, maxHeight: effectiveMaxHeight }));
|
|
66
71
|
};
|
|
67
|
-
export const MultilineInput = ({ value, onChange, onSubmit, placeholder, showCursor = true, width, isActive = true, onCursorChange, cursorOverride, onBoundaryArrow, undoDebounceMs, pasteThreshold, formatPastePlaceholder, images, onImagesChange, onPasteError, enableImagePaste = false, maxImageSizeBytes, maxImageCount, acceptedMimeTypes, maxHeight, }) => {
|
|
72
|
+
export const MultilineInput = ({ value, onChange, onSubmit, placeholder, showCursor = true, width, isActive = true, onCursorChange, cursorOverride, onBoundaryArrow, undoDebounceMs, pasteThreshold, formatPastePlaceholder, images, onImagesChange, onPasteError, enableImagePaste = false, maxImageSizeBytes, maxImageCount, acceptedMimeTypes, maxHeight, ignoreInput, }) => {
|
|
68
73
|
const terminalWidth = useTerminalWidth(width);
|
|
69
74
|
const { stdin } = useStdin();
|
|
70
75
|
const lastRawInput = useRef('');
|
|
71
76
|
const pasteActive = useRef(false);
|
|
72
77
|
const pasteBuffer = useRef('');
|
|
73
78
|
const suppressNextInput = useRef(false);
|
|
74
|
-
const textInput = useTextInput({
|
|
79
|
+
const textInput = useTextInput({
|
|
80
|
+
initialValue: value ?? '',
|
|
81
|
+
width: terminalWidth,
|
|
82
|
+
undoDebounceMs,
|
|
83
|
+
pasteThreshold,
|
|
84
|
+
formatPastePlaceholder,
|
|
85
|
+
});
|
|
75
86
|
const textInputRef = useRef(textInput);
|
|
76
87
|
useEffect(() => {
|
|
77
88
|
textInputRef.current = textInput;
|
|
@@ -209,22 +220,26 @@ export const MultilineInput = ({ value, onChange, onSubmit, placeholder, showCur
|
|
|
209
220
|
paste: handlePaste,
|
|
210
221
|
};
|
|
211
222
|
useInput((input, key) => {
|
|
223
|
+
if (ignoreInput?.(input, key)) {
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
212
226
|
if (suppressNextInput.current) {
|
|
213
227
|
// This stdin chunk is part of a bracketed paste — already handled by the
|
|
214
228
|
// raw 'data' listener. Don't dispatch as keystrokes.
|
|
215
229
|
suppressNextInput.current = false;
|
|
216
230
|
return;
|
|
217
231
|
}
|
|
218
|
-
log(`[USEINPUT] input=
|
|
232
|
+
log(`[USEINPUT] input='${input.replace(/[\x00-\x1F\x7F-]/g, (c) => `\\x${c.charCodeAt(0).toString(16)}`)}' key=${JSON.stringify(key)} rawLen=${lastRawInput.current?.length || 0}`);
|
|
219
233
|
// Detect if this is an Alt keypress for symbol keys (like Alt+\ or Alt+/)
|
|
220
234
|
// Standard Alt keypresses send ESC (\x1b) followed by the character.
|
|
221
235
|
// We check if it is a 2-character sequence starting with ESC, excluding CSI/SS3 prefixes ('[' or 'O')
|
|
222
236
|
const raw = lastRawInput.current;
|
|
223
|
-
const isMeta = key.meta ||
|
|
224
|
-
raw
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
237
|
+
const isMeta = key.meta ||
|
|
238
|
+
(raw &&
|
|
239
|
+
raw.length === 2 &&
|
|
240
|
+
raw.startsWith('\x1b') &&
|
|
241
|
+
raw[1] !== '[' &&
|
|
242
|
+
raw[1] !== 'O');
|
|
228
243
|
const updatedKey = isMeta ? { ...key, meta: true } : key;
|
|
229
244
|
handleKey(updatedKey, input, textInput.buffer, actions, textInput.cursor, lastRawInput.current, terminalWidth);
|
|
230
245
|
}, { isActive });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ink-prompt",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "A React Ink component for prompts",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@testing-library/react": "^16.3.0",
|
|
47
|
-
"@types/node": "^20.
|
|
47
|
+
"@types/node": "^20.19.41",
|
|
48
48
|
"@types/react": "^19.0.0",
|
|
49
49
|
"@vitest/ui": "^4.0.15",
|
|
50
50
|
"happy-dom": "^20.0.11",
|