mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-20 16:57:46 +00:00
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.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user