@@ -6,6 +6,11 @@ use colored::Colorize;
66use rustyline:: error:: ReadlineError ;
77use rustyline:: DefaultEditor ;
88use std:: path:: PathBuf ;
9+ use std:: sync:: atomic:: { AtomicBool , Ordering } ;
10+ use std:: sync:: Arc ;
11+ use std:: thread;
12+ use std:: time:: Duration ;
13+ use std:: io:: { self , Write } ;
914
1015pub struct Repl {
1116 client : AnthropicClient ,
@@ -299,8 +304,26 @@ impl Repl {
299304 }
300305
301306 // After executing tools, get another response from Claude
302- println ! ( "{}" , "Generating response..." . dimmed( ) ) ;
307+ // Start thinking animation
308+ let thinking = Arc :: new ( AtomicBool :: new ( true ) ) ;
309+ let thinking_clone = Arc :: clone ( & thinking) ;
303310
311+ let animation_handle = thread:: spawn ( move || {
312+ let frames = [ "⠋" , "⠙" , "⠹" , "⠸" , "⠼" , "⠴" , "⠦" , "⠧" , "⠇" , "⠏" ] ;
313+ let mut frame_idx = 0 ;
314+
315+ while thinking_clone. load ( Ordering :: Relaxed ) {
316+ print ! ( "\r {} {}" , frames[ frame_idx] . bright_cyan( ) , "Thinking..." . bright_cyan( ) ) ;
317+ let _ = io:: stdout ( ) . flush ( ) ;
318+ frame_idx = ( frame_idx + 1 ) % frames. len ( ) ;
319+ thread:: sleep ( Duration :: from_millis ( 80 ) ) ;
320+ }
321+
322+ // Clear the line
323+ print ! ( "\r {}\r " , " " . repeat( 20 ) ) ;
324+ let _ = io:: stdout ( ) . flush ( ) ;
325+ } ) ;
326+
304327 // Debug: show conversation history
305328 if std:: env:: var ( "SOFOS_DEBUG" ) . is_ok ( ) {
306329 eprintln ! ( "\n === DEBUG: Conversation before API call ===" ) ;
@@ -324,8 +347,16 @@ impl Repl {
324347 } ;
325348
326349 let response = match runtime. block_on ( self . client . create_message ( request) ) {
327- Ok ( resp) => resp,
350+ Ok ( resp) => {
351+ // Stop animation
352+ thinking. store ( false , Ordering :: Relaxed ) ;
353+ let _ = animation_handle. join ( ) ;
354+ resp
355+ } ,
328356 Err ( e) => {
357+ // Stop animation on error
358+ thinking. store ( false , Ordering :: Relaxed ) ;
359+ let _ = animation_handle. join ( ) ;
329360 eprintln ! ( "{} Failed to get response after tool execution: {}" , "Error:" . bright_red( ) . bold( ) , e) ;
330361 return Err ( e) ;
331362 }
0 commit comments