File tree Expand file tree Collapse file tree 1 file changed +26
-4
lines changed
crates/chat-cli/src/cli/chat Expand file tree Collapse file tree 1 file changed +26
-4
lines changed Original file line number Diff line number Diff line change @@ -24,7 +24,11 @@ use std::collections::{
24
24
HashSet ,
25
25
VecDeque ,
26
26
} ;
27
- use std:: io:: Write ;
27
+ use std:: io:: {
28
+ IsTerminal ,
29
+ Read ,
30
+ Write ,
31
+ } ;
28
32
use std:: process:: ExitCode ;
29
33
use std:: time:: Duration ;
30
34
@@ -181,8 +185,26 @@ pub struct ChatArgs {
181
185
182
186
impl ChatArgs {
183
187
pub async fn execute ( self , os : & mut Os ) -> Result < ExitCode > {
184
- if self . non_interactive && self . input . is_none ( ) {
185
- bail ! ( "Input must be supplied when running in non-interactive mode" ) ;
188
+ let mut input = self . input ;
189
+
190
+ if self . non_interactive && input. is_none ( ) {
191
+ if !std:: io:: stdin ( ) . is_terminal ( ) {
192
+ let mut buffer = String :: new ( ) ;
193
+ match std:: io:: stdin ( ) . read_to_string ( & mut buffer) {
194
+ Ok ( _) => {
195
+ if !buffer. trim ( ) . is_empty ( ) {
196
+ input = Some ( buffer. trim ( ) . to_string ( ) ) ;
197
+ }
198
+ } ,
199
+ Err ( e) => {
200
+ eprintln ! ( "Error reading from stdin: {}" , e) ;
201
+ } ,
202
+ }
203
+ }
204
+
205
+ if input. is_none ( ) {
206
+ bail ! ( "Input must be supplied when running in non-interactive mode" ) ;
207
+ }
186
208
}
187
209
188
210
let stdout = std:: io:: stdout ( ) ;
@@ -289,7 +311,7 @@ impl ChatArgs {
289
311
stdout,
290
312
stderr,
291
313
& conversation_id,
292
- self . input ,
314
+ input,
293
315
InputSource :: new ( os, prompt_request_sender, prompt_response_receiver) ?,
294
316
self . resume ,
295
317
|| terminal:: window_size ( ) . map ( |s| s. columns . into ( ) ) . ok ( ) ,
You can’t perform that action at this time.
0 commit comments