diff options
| author | Allen Hutchison <[email protected]> | 2025-04-21 17:41:44 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-04-21 17:41:44 -0700 |
| commit | 1a167b2ea5ef10d0bea66e227bd2148d4934f5b5 (patch) | |
| tree | c1f6732e92dddee97e5aa484671887200e092e75 /packages/cli/src/ui/App.tsx | |
| parent | cacf0cc0ef97f781ec742ff883c70ee7b0a04cee (diff) | |
Piped input (#104)
* New method for handling stdin. Bypass Ink, and output to stdout. Makes the CLI work like a typical Unix application when called with piped input.
* Fixing a few post-merge errors.
* Format code.
* Clean up lint and format errors.
Diffstat (limited to 'packages/cli/src/ui/App.tsx')
| -rw-r--r-- | packages/cli/src/ui/App.tsx | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/packages/cli/src/ui/App.tsx b/packages/cli/src/ui/App.tsx index f3e8b742..3bfb73db 100644 --- a/packages/cli/src/ui/App.tsx +++ b/packages/cli/src/ui/App.tsx @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -import React, { useState, useMemo } from 'react'; +import React, { useState, useMemo, useEffect } from 'react'; // Added useEffect import { Box, Text } from 'ink'; import { StreamingState, type HistoryItem } from './types.js'; import { useGeminiStream } from './hooks/useGeminiStream.js'; @@ -25,9 +25,11 @@ import { Colors } from './colors.js'; interface AppProps { config: Config; + initialInput?: string; // Added optional prop } -export const App = ({ config }: AppProps) => { +export const App = ({ config, initialInput }: AppProps) => { + // Destructured prop const [history, setHistory] = useState<HistoryItem[]>([]); const [startupWarnings, setStartupWarnings] = useState<string[]>([]); const { streamingState, submitQuery, initError, debugMessage } = @@ -38,6 +40,15 @@ export const App = ({ config }: AppProps) => { useStartupWarnings(setStartupWarnings); useInitializationErrorEffect(initError, history, setHistory); + // Effect to handle initial piped input + useEffect(() => { + if (initialInput && initialInput.trim() !== '') { + submitQuery(initialInput); + } + // Run only once on mount + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []); + const userMessages = useMemo( () => history |
