11use crate :: {
22 accessors,
3+ cmdbar:: CommandBar ,
34 components:: {
45 event_pump, CommandBlocking , CommandInfo , CommitComponent ,
56 Component , DrawableComponent , HelpComponent , MsgComponent ,
@@ -15,15 +16,13 @@ use anyhow::{anyhow, Result};
1516use asyncgit:: { sync, AsyncNotification , CWD } ;
1617use crossbeam_channel:: Sender ;
1718use crossterm:: event:: Event ;
18- use itertools:: Itertools ;
19- use std:: borrow:: Cow ;
2019use strings:: commands;
2120use tui:: {
2221 backend:: Backend ,
23- layout:: { Alignment , Constraint , Direction , Layout , Rect } ,
22+ layout:: { Constraint , Direction , Layout , Rect } ,
2423 style:: Modifier ,
2524 style:: Style ,
26- widgets:: { Block , Borders , Paragraph , Tabs , Text } ,
25+ widgets:: { Block , Borders , Tabs } ,
2726 Frame ,
2827} ;
2928///
@@ -34,7 +33,7 @@ pub struct App {
3433 reset : ResetComponent ,
3534 commit : CommitComponent ,
3635 stashmsg_popup : StashMsgComponent ,
37- current_commands : Vec < CommandInfo > ,
36+ cmdbar : CommandBar ,
3837 tab : usize ,
3938 revlog : Revlog ,
4039 status_tab : Status ,
@@ -60,7 +59,7 @@ impl App {
6059 & theme,
6160 ) ,
6261 do_quit : false ,
63- current_commands : Vec :: new ( ) ,
62+ cmdbar : CommandBar :: new ( & theme ) ,
6463 help : HelpComponent :: new ( & theme) ,
6564 msg : MsgComponent :: new ( & theme) ,
6665 tab : 0 ,
@@ -78,17 +77,23 @@ impl App {
7877 & mut self ,
7978 f : & mut Frame < B > ,
8079 ) -> Result < ( ) > {
80+ let fsize = f. size ( ) ;
81+
82+ self . cmdbar . refresh_width ( fsize. width ) ;
83+
8184 let chunks_main = Layout :: default ( )
8285 . direction ( Direction :: Vertical )
8386 . constraints (
8487 [
8588 Constraint :: Length ( 2 ) ,
8689 Constraint :: Min ( 2 ) ,
87- Constraint :: Length ( 1 ) ,
90+ Constraint :: Length ( self . cmdbar . height ( ) ) ,
8891 ]
8992 . as_ref ( ) ,
9093 )
91- . split ( f. size ( ) ) ;
94+ . split ( fsize) ;
95+
96+ self . cmdbar . draw ( f, chunks_main[ 2 ] ) ;
9297
9398 self . draw_tabs ( f, chunks_main[ 0 ] ) ;
9499
@@ -101,13 +106,6 @@ impl App {
101106 _ => return Err ( anyhow ! ( "unknown tab" ) ) ,
102107 } ;
103108
104- Self :: draw_commands (
105- f,
106- chunks_main[ 2 ] ,
107- self . current_commands . as_slice ( ) ,
108- self . theme ,
109- ) ;
110-
111109 self . draw_popups ( f) ?;
112110
113111 Ok ( ( ) )
@@ -135,6 +133,10 @@ impl App {
135133 self . toggle_tabs ( true ) ?;
136134 NeedsUpdate :: COMMANDS
137135 }
136+ keys:: CMD_BAR_TOGGLE => {
137+ self . cmdbar . toggle_more ( ) ;
138+ NeedsUpdate :: empty ( )
139+ }
138140
139141 _ => NeedsUpdate :: empty ( ) ,
140142 } ;
@@ -267,8 +269,7 @@ impl App {
267269
268270 fn update_commands ( & mut self ) {
269271 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 ) ) ;
272273 }
273274
274275 fn process_queue ( & mut self ) -> Result < NeedsUpdate > {
@@ -417,36 +418,4 @@ impl App {
417418 r,
418419 ) ;
419420 }
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- }
452421}
0 commit comments