blob: 86e760ee2ab2b986e15c93486d04a2cd93811136 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import React from 'react';
import { Box, useInput, useFocus } from 'ink';
import TextInput from 'ink-text-input';
interface InputPromptProps {
onSubmit: (value: string) => void;
}
export const InputPrompt: React.FC<InputPromptProps> = ({ onSubmit }) => {
const [value, setValue] = React.useState('');
const { isFocused } = useFocus({ autoFocus: true });
useInput(
(input, key) => {
if (key.return) {
if (value.trim()) {
onSubmit(value);
setValue('');
}
}
},
{ isActive: isFocused },
);
return (
<Box
borderStyle="round"
borderColor={isFocused ? 'blue' : 'gray'}
paddingX={1}
>
<TextInput
value={value}
onChange={setValue}
placeholder="Enter your message or use tools..."
onSubmit={() => {
/* Empty to prevent double submission */
}}
/>
</Box>
);
};
|