@@ -2533,41 +2533,62 @@ impl ChatContext {
25332533 let left_over_width = progress_bar_width
25342534 - std:: cmp:: min ( context_width + assistant_width + user_width, progress_bar_width) ;
25352535
2536- queue ! (
2537- self . output,
2538- style:: Print ( format!(
2539- "\n Current context window ({} of {}k tokens used)\n " ,
2540- total_token_used,
2541- CONTEXT_WINDOW_SIZE / 1000
2542- ) ) ,
2543- style:: SetForegroundColor ( Color :: DarkCyan ) ,
2544- // add a nice visual to mimic "tiny" progress, so the overral progress bar doesn't look too
2545- // empty
2546- style:: Print ( "|" . repeat( if context_width == 0 && * context_token_count > 0 {
2547- 1
2548- } else {
2549- 0
2550- } ) ) ,
2551- style:: Print ( "█" . repeat( context_width) ) ,
2552- style:: SetForegroundColor ( Color :: Blue ) ,
2553- style:: Print ( "|" . repeat( if assistant_width == 0 && * assistant_token_count > 0 {
2554- 1
2555- } else {
2556- 0
2557- } ) ) ,
2558- style:: Print ( "█" . repeat( assistant_width) ) ,
2559- style:: SetForegroundColor ( Color :: Magenta ) ,
2560- style:: Print ( "|" . repeat( if user_width == 0 && * user_token_count > 0 { 1 } else { 0 } ) ) ,
2561- style:: Print ( "█" . repeat( user_width) ) ,
2562- style:: SetForegroundColor ( Color :: DarkGrey ) ,
2563- style:: Print ( "█" . repeat( left_over_width) ) ,
2564- style:: Print ( " " ) ,
2565- style:: SetForegroundColor ( Color :: Reset ) ,
2566- style:: Print ( format!(
2567- "{:.2}%" ,
2568- ( total_token_used. value( ) as f32 / CONTEXT_WINDOW_SIZE as f32 ) * 100.0
2569- ) ) ,
2570- ) ?;
2536+ let is_overflow = ( context_width + assistant_width + user_width) > progress_bar_width;
2537+
2538+ if is_overflow {
2539+ queue ! (
2540+ self . output,
2541+ style:: Print ( format!(
2542+ "\n Current context window ({} of {}k tokens used)\n " ,
2543+ total_token_used,
2544+ CONTEXT_WINDOW_SIZE / 1000
2545+ ) ) ,
2546+ style:: SetForegroundColor ( Color :: DarkRed ) ,
2547+ style:: Print ( "█" . repeat( progress_bar_width) ) ,
2548+ style:: SetForegroundColor ( Color :: Reset ) ,
2549+ style:: Print ( " " ) ,
2550+ style:: Print ( format!(
2551+ "{:.2}%" ,
2552+ ( total_token_used. value( ) as f32 / CONTEXT_WINDOW_SIZE as f32 ) * 100.0
2553+ ) ) ,
2554+ ) ?;
2555+ } else {
2556+ queue ! (
2557+ self . output,
2558+ style:: Print ( format!(
2559+ "\n Current context window ({} of {}k tokens used)\n " ,
2560+ total_token_used,
2561+ CONTEXT_WINDOW_SIZE / 1000
2562+ ) ) ,
2563+ style:: SetForegroundColor ( Color :: DarkCyan ) ,
2564+ // add a nice visual to mimic "tiny" progress, so the overral progress bar doesn't look too
2565+ // empty
2566+ style:: Print ( "|" . repeat( if context_width == 0 && * context_token_count > 0 {
2567+ 1
2568+ } else {
2569+ 0
2570+ } ) ) ,
2571+ style:: Print ( "█" . repeat( context_width) ) ,
2572+ style:: SetForegroundColor ( Color :: Blue ) ,
2573+ style:: Print ( "|" . repeat( if assistant_width == 0 && * assistant_token_count > 0 {
2574+ 1
2575+ } else {
2576+ 0
2577+ } ) ) ,
2578+ style:: Print ( "█" . repeat( assistant_width) ) ,
2579+ style:: SetForegroundColor ( Color :: Magenta ) ,
2580+ style:: Print ( "|" . repeat( if user_width == 0 && * user_token_count > 0 { 1 } else { 0 } ) ) ,
2581+ style:: Print ( "█" . repeat( user_width) ) ,
2582+ style:: SetForegroundColor ( Color :: DarkGrey ) ,
2583+ style:: Print ( "█" . repeat( left_over_width) ) ,
2584+ style:: Print ( " " ) ,
2585+ style:: SetForegroundColor ( Color :: Reset ) ,
2586+ style:: Print ( format!(
2587+ "{:.2}%" ,
2588+ ( total_token_used. value( ) as f32 / CONTEXT_WINDOW_SIZE as f32 ) * 100.0
2589+ ) ) ,
2590+ ) ?;
2591+ }
25712592
25722593 queue ! ( self . output, style:: Print ( "\n \n " ) ) ?;
25732594 self . output . flush ( ) ?;
0 commit comments