@@ -14,14 +14,16 @@ use anyhow::Result;
1414use asyncgit:: {
1515 cached,
1616 sync:: BranchCompare ,
17- sync:: { self , status:: StatusType } ,
17+ sync:: { self , status:: StatusType , RepoState } ,
1818 AsyncDiff , AsyncNotification , AsyncStatus , DiffParams , DiffType ,
1919 StatusParams , CWD ,
2020} ;
2121use crossbeam_channel:: Sender ;
2222use crossterm:: event:: Event ;
23+ use std:: convert:: TryFrom ;
2324use tui:: {
2425 layout:: { Alignment , Constraint , Direction , Layout } ,
26+ style:: { Color , Style } ,
2527 widgets:: Paragraph ,
2628} ;
2729
@@ -199,20 +201,27 @@ impl Status {
199201 f : & mut tui:: Frame < B > ,
200202 r : tui:: layout:: Rect ,
201203 ) {
202- let w = Paragraph :: new ( format ! (
203- "{:?}" ,
204- asyncgit:: sync:: repo_state( CWD ) . expect( "" )
205- ) )
206- . alignment ( Alignment :: Left ) ;
207-
208- let mut rect = r;
209- rect. x += 1 ;
210- rect. width = rect. width . saturating_sub ( 2 ) ;
211- rect. y += rect. height . saturating_sub ( 1 ) ;
212- rect. height =
213- rect. height . saturating_sub ( rect. height . saturating_sub ( 1 ) ) ;
214-
215- f. render_widget ( w, rect) ;
204+ if let Ok ( state) = asyncgit:: sync:: repo_state ( CWD ) {
205+ if state != RepoState :: Clean {
206+ let txt = format ! ( "{:?}" , state) ;
207+ let txt_len = u16:: try_from ( txt. len ( ) )
208+ . expect ( "state name too long" ) ;
209+ let w = Paragraph :: new ( txt)
210+ . style ( Style :: default ( ) . fg ( Color :: Red ) )
211+ . alignment ( Alignment :: Left ) ;
212+
213+ let mut rect = r;
214+ rect. x += 1 ;
215+ rect. width =
216+ rect. width . saturating_sub ( 2 ) . min ( txt_len) ;
217+ rect. y += rect. height . saturating_sub ( 1 ) ;
218+ rect. height = rect
219+ . height
220+ . saturating_sub ( rect. height . saturating_sub ( 1 ) ) ;
221+
222+ f. render_widget ( w, rect) ;
223+ }
224+ }
216225 }
217226
218227 fn can_focus_diff ( & self ) -> bool {
@@ -287,7 +296,7 @@ impl Status {
287296 self . git_status_stage
288297 . fetch ( StatusParams :: new ( StatusType :: Stage , true ) ) ?;
289298
290- self . check_branch_state ( ) ;
299+ self . branch_compare ( ) ;
291300 }
292301
293302 Ok ( ( ) )
@@ -422,7 +431,7 @@ impl Status {
422431 }
423432 }
424433
425- fn check_branch_state ( & mut self ) {
434+ fn branch_compare ( & mut self ) {
426435 self . git_branch_state =
427436 self . git_branch_name . last ( ) . and_then ( |branch| {
428437 sync:: branch_compare_upstream ( CWD , branch. as_str ( ) )
0 commit comments