UNPKG

terminal-chat-ui

Version:

Shared UI components for terminal-based chat interfaces using Theater actors

37 lines (36 loc) 1.65 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; /** * SimpleInput - basic single-line input (from git-agent style) */ import { Box, Text, useInput } from 'ink'; import { useState } from 'react'; /** * Simple, lightweight input component for quick interactions */ export function SimpleInput({ placeholder = '> ', onSubmit, disabled = false, value: controlledValue, onChange }) { const [internalValue, setInternalValue] = useState(''); // Support both controlled and uncontrolled modes const isControlled = controlledValue !== undefined; const value = isControlled ? controlledValue : internalValue; const setValue = isControlled ? (onChange || (() => { })) : setInternalValue; useInput((input, key) => { if (disabled) return; if (key.return) { // Submit on Enter if (value.trim()) { onSubmit(value.trim()); if (!isControlled) { setInternalValue(''); } } } else if (key.backspace || key.delete) { setValue(value.slice(0, -1)); } else if (input && !key.ctrl && !key.meta) { setValue(value + input); } }); return (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Box, { children: [_jsx(Text, { color: "gray", children: placeholder }), _jsx(Text, { color: "white", children: value }), !disabled && _jsx(Text, { backgroundColor: "gray", children: " " })] }), !disabled && (_jsx(Box, { marginTop: 1, children: _jsx(Text, { color: "gray", dimColor: true, children: "Press Enter to send" }) }))] })); }