@@ -290,19 +290,13 @@ fn parse_session_info_bytes(input: &[u8]) -> SessionInfo {
290290 . or_else ( || root. get ( "cost_usd" ) . and_then ( json_f64) ) ;
291291
292292 // total_duration_ms: /cost/total_duration_ms
293- let total_duration_ms = root
294- . pointer ( "/cost/total_duration_ms" )
295- . and_then ( json_u64) ;
293+ let total_duration_ms = root. pointer ( "/cost/total_duration_ms" ) . and_then ( json_u64) ;
296294
297295 // lines_added: /cost/total_lines_added
298- let lines_added = root
299- . pointer ( "/cost/total_lines_added" )
300- . and_then ( json_u64) ;
296+ let lines_added = root. pointer ( "/cost/total_lines_added" ) . and_then ( json_u64) ;
301297
302298 // lines_removed: /cost/total_lines_removed
303- let lines_removed = root
304- . pointer ( "/cost/total_lines_removed" )
305- . and_then ( json_u64) ;
299+ let lines_removed = root. pointer ( "/cost/total_lines_removed" ) . and_then ( json_u64) ;
306300
307301 // context_tokens: sum /context_window/total_input_tokens + total_output_tokens
308302 // -> /context_tokens (flat)
@@ -321,7 +315,10 @@ fn parse_session_info_bytes(input: &[u8]) -> SessionInfo {
321315 ( None , None ) => root
322316 . get ( "context_tokens" )
323317 . and_then ( json_u64)
324- . or_else ( || root. pointer ( "/context_window/used_tokens" ) . and_then ( json_u64) )
318+ . or_else ( || {
319+ root. pointer ( "/context_window/used_tokens" )
320+ . and_then ( json_u64)
321+ } )
325322 . or_else ( || root. pointer ( "/context_window/used" ) . and_then ( json_u64) ) ,
326323 }
327324 } ;
@@ -334,7 +331,10 @@ fn parse_session_info_bytes(input: &[u8]) -> SessionInfo {
334331 . pointer ( "/context_window/context_window_size" )
335332 . and_then ( json_u64)
336333 . or_else ( || root. get ( "context_window" ) . and_then ( json_u64) )
337- . or_else ( || root. pointer ( "/context_window/max_tokens" ) . and_then ( json_u64) )
334+ . or_else ( || {
335+ root. pointer ( "/context_window/max_tokens" )
336+ . and_then ( json_u64)
337+ } )
338338 . or_else ( || root. pointer ( "/context_window/max" ) . and_then ( json_u64) ) ;
339339
340340 // used_percentage: /context_window/used_percentage
@@ -343,9 +343,7 @@ fn parse_session_info_bytes(input: &[u8]) -> SessionInfo {
343343 . and_then ( json_f64) ;
344344
345345 // exceeds_200k: /exceeds_200k_tokens
346- let exceeds_200k = root
347- . get ( "exceeds_200k_tokens" )
348- . and_then ( |v| v. as_bool ( ) ) ;
346+ let exceeds_200k = root. get ( "exceeds_200k_tokens" ) . and_then ( |v| v. as_bool ( ) ) ;
349347
350348 // session_id: /session_id
351349 let session_id = root. get ( "session_id" ) . and_then ( json_string) ;
@@ -616,16 +614,14 @@ fn render_cost(session: &SessionInfo) -> Option<String> {
616614/// Medium/narrow: 42%
617615fn render_context_bar ( session : & SessionInfo , width : u16 , use_unicode : bool ) -> Option < String > {
618616 // Get percentage: prefer used_percentage, fallback to calculation
619- let pct = session
620- . used_percentage
621- . or_else ( || {
622- let tokens = session. context_tokens ? as f64 ;
623- let window = session. context_window ? as f64 ;
624- if window == 0.0 {
625- return None ;
626- }
627- Some ( ( tokens / window) * 100.0 )
628- } ) ?;
617+ let pct = session. used_percentage . or_else ( || {
618+ let tokens = session. context_tokens ? as f64 ;
619+ let window = session. context_window ? as f64 ;
620+ if window == 0.0 {
621+ return None ;
622+ }
623+ Some ( ( tokens / window) * 100.0 )
624+ } ) ?;
629625
630626 let pct_clamped = pct. clamp ( 0.0 , 100.0 ) ;
631627
@@ -665,10 +661,7 @@ fn render_context_bar(session: &SessionInfo, width: u16, use_unicode: bool) -> O
665661
666662/// Render the model display name, dimmed.
667663fn render_model ( session : & SessionInfo ) -> Option < String > {
668- session
669- . model_name
670- . as_ref ( )
671- . map ( |m| m. dimmed ( ) . to_string ( ) )
664+ session. model_name . as_ref ( ) . map ( |m| m. dimmed ( ) . to_string ( ) )
672665}
673666
674667/// Render lines changed segment (e.g. "+12 -3").
@@ -837,9 +830,12 @@ fn has_loop(state: &LoopState) -> bool {
837830
838831/// Returns true if any agent is in an active state (Running, Queued, or Error).
839832fn is_loop_active ( agents : & [ AgentState ] ) -> bool {
840- agents
841- . iter ( )
842- . any ( |a| matches ! ( a. status, AgentStatus :: Running | AgentStatus :: Queued | AgentStatus :: Error ) )
833+ agents. iter ( ) . any ( |a| {
834+ matches ! (
835+ a. status,
836+ AgentStatus :: Running | AgentStatus :: Queued | AgentStatus :: Error
837+ )
838+ } )
843839}
844840
845841// ---------------------------------------------------------------------------
@@ -1386,7 +1382,11 @@ session_timeout_secs = 60
13861382 } ;
13871383 let config = StatuslineConfig :: default ( ) ;
13881384 let line = render ( & session, & state, & config, 150 , true , false , false ) ;
1389- assert ! ( line. contains( "loop" ) , "active loop should show 'loop': {}" , line) ;
1385+ assert ! (
1386+ line. contains( "loop" ) ,
1387+ "active loop should show 'loop': {}" ,
1388+ line
1389+ ) ;
13901390 assert ! ( line. contains( "$0.14" ) , "should show cost: {}" , line) ;
13911391 assert ! ( line. contains( "22%" ) , "should show context %: {}" , line) ;
13921392 }
@@ -1571,14 +1571,12 @@ session_timeout_secs = 60
15711571 } ;
15721572 let state = LoopState {
15731573 started_at : Some ( 0 ) ,
1574- agents : vec ! [
1575- AgentState {
1576- id: 1 ,
1577- name: "a" . into( ) ,
1578- status: AgentStatus :: Running ,
1579- updated_at: 0 ,
1580- } ,
1581- ] ,
1574+ agents : vec ! [ AgentState {
1575+ id: 1 ,
1576+ name: "a" . into( ) ,
1577+ status: AgentStatus :: Running ,
1578+ updated_at: 0 ,
1579+ } ] ,
15821580 ..Default :: default ( )
15831581 } ;
15841582 let config = StatuslineConfig :: default ( ) ;
@@ -1788,11 +1786,7 @@ session_timeout_secs = 60
17881786 assert ! ( result. is_some( ) ) ;
17891787 let r = result. unwrap ( ) ;
17901788 assert ! ( r. contains( "30%" ) , "should contain 30%: {}" , r) ;
1791- assert ! (
1792- r. contains( '\u{2588}' ) ,
1793- "wide mode should have bar: {}" ,
1794- r
1795- ) ;
1789+ assert ! ( r. contains( '\u{2588}' ) , "wide mode should have bar: {}" , r) ;
17961790 }
17971791
17981792 #[ test]
@@ -1827,11 +1821,7 @@ session_timeout_secs = 60
18271821 let result = render_context_bar ( & session, 150 , false ) ;
18281822 let r = result. unwrap ( ) ;
18291823 assert ! ( r. contains( '#' ) , "ASCII mode should use # for filled: {}" , r) ;
1830- assert ! (
1831- r. contains( '-' ) ,
1832- "ASCII mode should use - for empty: {}" ,
1833- r
1834- ) ;
1824+ assert ! ( r. contains( '-' ) , "ASCII mode should use - for empty: {}" , r) ;
18351825 }
18361826
18371827 #[ test]
@@ -1899,11 +1889,7 @@ session_timeout_secs = 60
18991889 "State A should not contain 'loop': {}" ,
19001890 line
19011891 ) ;
1902- assert ! (
1903- line. contains( "$0.14" ) ,
1904- "State A should show cost: {}" ,
1905- line
1906- ) ;
1892+ assert ! ( line. contains( "$0.14" ) , "State A should show cost: {}" , line) ;
19071893 assert ! (
19081894 line. contains( "42%" ) ,
19091895 "State A should show context %: {}" ,
@@ -2009,17 +1995,12 @@ session_timeout_secs = 60
20091995 "State C should contain 'loop': {}" ,
20101996 line
20111997 ) ;
2012- assert ! (
2013- line. contains( "$0.14" ) ,
2014- "State C should show cost: {}" ,
2015- line
2016- ) ;
1998+ assert ! ( line. contains( "$0.14" ) , "State C should show cost: {}" , line) ;
20171999 }
20182000
20192001 #[ test]
20202002 fn test_used_percentage_direct ( ) {
2021- let json =
2022- r#"{"context_window":{"used_percentage":42.5,"context_window_size":200000}}"# ;
2003+ let json = r#"{"context_window":{"used_percentage":42.5,"context_window_size":200000}}"# ;
20232004 let info = parse_session_info_bytes ( json. as_bytes ( ) ) ;
20242005 assert ! ( ( info. used_percentage. unwrap( ) - 42.5 ) . abs( ) < f64 :: EPSILON ) ;
20252006 assert_eq ! ( info. context_window, Some ( 200000 ) ) ;
0 commit comments