1
1
use crate :: {
2
2
accessors,
3
+ cmdbar:: CommandBar ,
3
4
components:: {
4
5
event_pump, CommandBlocking , CommandInfo , CommitComponent ,
5
6
Component , DrawableComponent , HelpComponent , MsgComponent ,
@@ -15,15 +16,13 @@ use anyhow::{anyhow, Result};
15
16
use asyncgit:: { sync, AsyncNotification , CWD } ;
16
17
use crossbeam_channel:: Sender ;
17
18
use crossterm:: event:: Event ;
18
- use itertools:: Itertools ;
19
- use std:: borrow:: Cow ;
20
19
use strings:: commands;
21
20
use tui:: {
22
21
backend:: Backend ,
23
- layout:: { Alignment , Constraint , Direction , Layout , Rect } ,
22
+ layout:: { Constraint , Direction , Layout , Rect } ,
24
23
style:: Modifier ,
25
24
style:: Style ,
26
- widgets:: { Block , Borders , Paragraph , Tabs , Text } ,
25
+ widgets:: { Block , Borders , Tabs } ,
27
26
Frame ,
28
27
} ;
29
28
///
@@ -34,7 +33,7 @@ pub struct App {
34
33
reset : ResetComponent ,
35
34
commit : CommitComponent ,
36
35
stashmsg_popup : StashMsgComponent ,
37
- current_commands : Vec < CommandInfo > ,
36
+ cmdbar : CommandBar ,
38
37
tab : usize ,
39
38
revlog : Revlog ,
40
39
status_tab : Status ,
@@ -60,7 +59,7 @@ impl App {
60
59
& theme,
61
60
) ,
62
61
do_quit : false ,
63
- current_commands : Vec :: new ( ) ,
62
+ cmdbar : CommandBar :: new ( & theme ) ,
64
63
help : HelpComponent :: new ( & theme) ,
65
64
msg : MsgComponent :: new ( & theme) ,
66
65
tab : 0 ,
@@ -78,17 +77,23 @@ impl App {
78
77
& mut self ,
79
78
f : & mut Frame < B > ,
80
79
) -> Result < ( ) > {
80
+ let fsize = f. size ( ) ;
81
+
82
+ self . cmdbar . refresh_width ( fsize. width ) ;
83
+
81
84
let chunks_main = Layout :: default ( )
82
85
. direction ( Direction :: Vertical )
83
86
. constraints (
84
87
[
85
88
Constraint :: Length ( 2 ) ,
86
89
Constraint :: Min ( 2 ) ,
87
- Constraint :: Length ( 1 ) ,
90
+ Constraint :: Length ( self . cmdbar . height ( ) ) ,
88
91
]
89
92
. as_ref ( ) ,
90
93
)
91
- . split ( f. size ( ) ) ;
94
+ . split ( fsize) ;
95
+
96
+ self . cmdbar . draw ( f, chunks_main[ 2 ] ) ;
92
97
93
98
self . draw_tabs ( f, chunks_main[ 0 ] ) ;
94
99
@@ -101,13 +106,6 @@ impl App {
101
106
_ => return Err ( anyhow ! ( "unknown tab" ) ) ,
102
107
} ;
103
108
104
- Self :: draw_commands (
105
- f,
106
- chunks_main[ 2 ] ,
107
- self . current_commands . as_slice ( ) ,
108
- self . theme ,
109
- ) ;
110
-
111
109
self . draw_popups ( f) ?;
112
110
113
111
Ok ( ( ) )
@@ -135,6 +133,10 @@ impl App {
135
133
self . toggle_tabs ( true ) ?;
136
134
NeedsUpdate :: COMMANDS
137
135
}
136
+ keys:: CMD_BAR_TOGGLE => {
137
+ self . cmdbar . toggle_more ( ) ;
138
+ NeedsUpdate :: empty ( )
139
+ }
138
140
139
141
_ => NeedsUpdate :: empty ( ) ,
140
142
} ;
@@ -267,8 +269,7 @@ impl App {
267
269
268
270
fn update_commands ( & mut self ) {
269
271
self . help . set_cmds ( self . commands ( true ) ) ;
270
- self . current_commands = self . commands ( false ) ;
271
- self . current_commands . sort_by_key ( |e| e. order ) ;
272
+ self . cmdbar . set_cmds ( self . commands ( false ) ) ;
272
273
}
273
274
274
275
fn process_queue ( & mut self ) -> Result < NeedsUpdate > {
@@ -417,36 +418,4 @@ impl App {
417
418
r,
418
419
) ;
419
420
}
420
-
421
- fn draw_commands < B : Backend > (
422
- f : & mut Frame < B > ,
423
- r : Rect ,
424
- cmds : & [ CommandInfo ] ,
425
- theme : Theme ,
426
- ) {
427
- let splitter = Text :: Styled (
428
- Cow :: from ( strings:: CMD_SPLITTER ) ,
429
- Style :: default ( ) ,
430
- ) ;
431
-
432
- let texts = cmds
433
- . iter ( )
434
- . filter_map ( |c| {
435
- if c. show_in_quickbar ( ) {
436
- Some ( Text :: Styled (
437
- Cow :: from ( c. text . name ) ,
438
- theme. toolbar ( c. enabled ) ,
439
- ) )
440
- } else {
441
- None
442
- }
443
- } )
444
- . collect :: < Vec < _ > > ( ) ;
445
-
446
- f. render_widget (
447
- Paragraph :: new ( texts. iter ( ) . intersperse ( & splitter) )
448
- . alignment ( Alignment :: Left ) ,
449
- r,
450
- ) ;
451
- }
452
421
}
0 commit comments