@@ -23,11 +23,10 @@ use crossbeam_channel::Sender;
23
23
use crossterm:: event:: Event ;
24
24
use itertools:: Itertools ;
25
25
use std:: convert:: Into ;
26
- use std:: convert:: TryFrom ;
27
26
use tui:: {
28
27
layout:: { Alignment , Constraint , Direction , Layout } ,
29
28
style:: { Color , Style } ,
30
- widgets:: Paragraph ,
29
+ widgets:: { Block , BorderType , Borders , Paragraph } ,
31
30
} ;
32
31
33
32
/// what part of the screen is focused
@@ -80,6 +79,19 @@ impl DrawableComponent for Status {
80
79
f : & mut tui:: Frame < B > ,
81
80
rect : tui:: layout:: Rect ,
82
81
) -> Result < ( ) > {
82
+ let repo_unclean = Self :: repo_state_unclean ( ) ;
83
+ let rects = if repo_unclean {
84
+ Layout :: default ( )
85
+ . direction ( Direction :: Vertical )
86
+ . constraints (
87
+ [ Constraint :: Min ( 1 ) , Constraint :: Length ( 3 ) ]
88
+ . as_ref ( ) ,
89
+ )
90
+ . split ( rect)
91
+ } else {
92
+ vec ! [ rect]
93
+ } ;
94
+
83
95
let chunks = Layout :: default ( )
84
96
. direction ( Direction :: Horizontal )
85
97
. constraints (
@@ -96,7 +108,7 @@ impl DrawableComponent for Status {
96
108
}
97
109
. as_ref ( ) ,
98
110
)
99
- . split ( rect ) ;
111
+ . split ( rects [ 0 ] ) ;
100
112
101
113
let left_chunks = Layout :: default ( )
102
114
. direction ( Direction :: Vertical )
@@ -120,7 +132,10 @@ impl DrawableComponent for Status {
120
132
self . index . draw ( f, left_chunks[ 1 ] ) ?;
121
133
self . diff . draw ( f, chunks[ 1 ] ) ?;
122
134
self . draw_branch_state ( f, & left_chunks) ;
123
- Self :: draw_repo_state ( f, left_chunks[ 0 ] ) ?;
135
+
136
+ if repo_unclean {
137
+ Self :: draw_repo_state ( f, rects[ 1 ] ) ;
138
+ }
124
139
125
140
Ok ( ( ) )
126
141
}
@@ -221,32 +236,27 @@ impl Status {
221
236
let ids =
222
237
sync:: mergehead_ids ( CWD ) . unwrap_or_default ( ) ;
223
238
224
- let ids = format ! (
225
- "({}) " ,
239
+ format ! (
240
+ "Commits: {} " ,
226
241
ids. iter( )
227
242
. map( sync:: CommitId :: get_short_string)
228
243
. join( "," )
229
- ) ;
230
-
231
- format ! ( "{:?} {}" , state, ids)
244
+ )
232
245
}
233
246
RepoState :: Rebase => {
234
- let progress =
235
- if let Ok ( p) = sync:: rebase_progress ( CWD ) {
236
- format ! (
237
- "[{}] {}/{}" ,
238
- p. current_commit
239
- . as_ref( )
240
- . map( CommitId :: get_short_string)
241
- . unwrap_or_default( ) ,
242
- p. current + 1 ,
243
- p. steps
244
- )
245
- } else {
246
- String :: new ( )
247
- } ;
248
-
249
- format ! ( "{:?} ({})" , state, progress)
247
+ if let Ok ( p) = sync:: rebase_progress ( CWD ) {
248
+ format ! (
249
+ "Step: {}/{} Current Commit: {}" ,
250
+ p. current + 1 ,
251
+ p. steps,
252
+ p. current_commit
253
+ . as_ref( )
254
+ . map( CommitId :: get_short_string)
255
+ . unwrap_or_default( ) ,
256
+ )
257
+ } else {
258
+ String :: new ( )
259
+ }
250
260
}
251
261
_ => format ! ( "{:?}" , state) ,
252
262
}
@@ -255,30 +265,36 @@ impl Status {
255
265
fn draw_repo_state < B : tui:: backend:: Backend > (
256
266
f : & mut tui:: Frame < B > ,
257
267
r : tui:: layout:: Rect ,
258
- ) -> Result < ( ) > {
268
+ ) {
259
269
if let Ok ( state) = sync:: repo_state ( CWD ) {
260
270
if state != RepoState :: Clean {
261
271
let txt = Self :: repo_state_text ( & state) ;
262
272
263
- let txt_len = u16:: try_from ( txt. len ( ) ) ?;
264
273
let w = Paragraph :: new ( txt)
274
+ . block (
275
+ Block :: default ( )
276
+ . border_type ( BorderType :: Plain )
277
+ . borders ( Borders :: all ( ) )
278
+ . border_style (
279
+ Style :: default ( ) . fg ( Color :: Yellow ) ,
280
+ )
281
+ . title ( format ! ( "Pending {:?}" , state) ) ,
282
+ )
265
283
. style ( Style :: default ( ) . fg ( Color :: Red ) )
266
284
. alignment ( Alignment :: Left ) ;
267
285
268
- let mut rect = r;
269
- rect. x += 1 ;
270
- rect. width =
271
- rect. width . saturating_sub ( 2 ) . min ( txt_len) ;
272
- rect. y += rect. height . saturating_sub ( 1 ) ;
273
- rect. height = rect
274
- . height
275
- . saturating_sub ( rect. height . saturating_sub ( 1 ) ) ;
276
-
277
- f. render_widget ( w, rect) ;
286
+ f. render_widget ( w, r) ;
278
287
}
279
288
}
289
+ }
280
290
281
- Ok ( ( ) )
291
+ fn repo_state_unclean ( ) -> bool {
292
+ if let Ok ( state) = sync:: repo_state ( CWD ) {
293
+ if state != RepoState :: Clean {
294
+ return true ;
295
+ }
296
+ }
297
+ false
282
298
}
283
299
284
300
fn can_focus_diff ( & self ) -> bool {
0 commit comments