@@ -14,14 +14,16 @@ use anyhow::Result;
14
14
use asyncgit:: {
15
15
cached,
16
16
sync:: BranchCompare ,
17
- sync:: { self , status:: StatusType } ,
17
+ sync:: { self , status:: StatusType , RepoState } ,
18
18
AsyncDiff , AsyncNotification , AsyncStatus , DiffParams , DiffType ,
19
19
StatusParams , CWD ,
20
20
} ;
21
21
use crossbeam_channel:: Sender ;
22
22
use crossterm:: event:: Event ;
23
+ use std:: convert:: TryFrom ;
23
24
use tui:: {
24
25
layout:: { Alignment , Constraint , Direction , Layout } ,
26
+ style:: { Color , Style } ,
25
27
widgets:: Paragraph ,
26
28
} ;
27
29
@@ -199,20 +201,27 @@ impl Status {
199
201
f : & mut tui:: Frame < B > ,
200
202
r : tui:: layout:: Rect ,
201
203
) {
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
+ }
216
225
}
217
226
218
227
fn can_focus_diff ( & self ) -> bool {
@@ -287,7 +296,7 @@ impl Status {
287
296
self . git_status_stage
288
297
. fetch ( StatusParams :: new ( StatusType :: Stage , true ) ) ?;
289
298
290
- self . check_branch_state ( ) ;
299
+ self . branch_compare ( ) ;
291
300
}
292
301
293
302
Ok ( ( ) )
@@ -422,7 +431,7 @@ impl Status {
422
431
}
423
432
}
424
433
425
- fn check_branch_state ( & mut self ) {
434
+ fn branch_compare ( & mut self ) {
426
435
self . git_branch_state =
427
436
self . git_branch_name . last ( ) . and_then ( |branch| {
428
437
sync:: branch_compare_upstream ( CWD , branch. as_str ( ) )
0 commit comments