From 3fce6cea27d3e6129d6c06e528b62e1b11bf7094 Mon Sep 17 00:00:00 2001 From: Evan Senter Date: Sat, 19 Apr 2025 19:45:42 +0100 Subject: Starting to modularize into separate cli / server packages. (#55) * Starting to move a lot of code into packages/server * More of the massive refactor, builds and runs, some issues though. * Fixing outstanding issue with double messages. * Fixing a minor UI issue. * Fixing the build post-merge. * Running formatting. * Addressing comments. --- packages/cli/src/ui/components/InputPrompt.tsx | 56 +++++++++++++------------- 1 file changed, 29 insertions(+), 27 deletions(-) (limited to 'packages/cli/src/ui/components/InputPrompt.tsx') diff --git a/packages/cli/src/ui/components/InputPrompt.tsx b/packages/cli/src/ui/components/InputPrompt.tsx index b5d0b2b5..86e760ee 100644 --- a/packages/cli/src/ui/components/InputPrompt.tsx +++ b/packages/cli/src/ui/components/InputPrompt.tsx @@ -5,41 +5,43 @@ */ import React from 'react'; -import { Box, Text } from 'ink'; +import { Box, useInput, useFocus } from 'ink'; import TextInput from 'ink-text-input'; -import { globalConfig } from '../../config/config.js'; interface InputPromptProps { - query: string; - setQuery: (value: string) => void; onSubmit: (value: string) => void; - isActive: boolean; - forceKey?: number; } -export const InputPrompt: React.FC = ({ - query, - setQuery, - onSubmit, - isActive, - forceKey, -}) => { - const model = globalConfig.getModel(); +export const InputPrompt: React.FC = ({ 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 ( - - > - - - + + { + /* Empty to prevent double submission */ + }} + /> ); }; -- cgit v1.2.3