@@ -22,14 +22,6 @@ use syntect::{
2222} ;
2323use syntect_tui:: into_span;
2424
25- /// helper function to create a centered rect using up certain percentage of the available rect `r`
26- fn popup_area ( area : Rect , x : u16 , y : u16 ) -> Rect {
27- let vertical = Layout :: vertical ( [ Constraint :: Length ( y) ] ) . flex ( Flex :: Center ) ;
28- let horizontal = Layout :: horizontal ( [ Constraint :: Percentage ( x) ] ) . flex ( Flex :: Center ) ;
29- let [ area] = vertical. areas ( area) ;
30- let [ area] = horizontal. areas ( area) ;
31- area
32- }
3325pub fn ui ( f : & mut Frame , model : & mut Model ) {
3426 if let AppState :: SelectCommand ( model) = & mut model. app_state {
3527 let main_and_key_bindings = Layout :: default ( )
@@ -56,24 +48,39 @@ pub fn ui(f: &mut Frame, model: &mut Model) {
5648 render_notification_block ( model, f, notification_and_current_version[ 0 ] ) ;
5749 render_current_version_block ( f, notification_and_current_version[ 1 ] ) ;
5850
59- let preview_and_commands = Layout :: default ( )
60- . direction ( Direction :: Vertical )
61- . constraints ( [ Constraint :: Percentage ( 70 ) , Constraint :: Percentage ( 30 ) ] )
62- . split ( main[ 0 ] ) ;
63- render_preview_block ( model, f, preview_and_commands[ 0 ] ) ;
51+ let commands = if f. area ( ) . height < HEIGHT_THRESHOLD_TO_HIDE_PREVIEW_WINDOW {
52+ let preview_and_commands = Layout :: default ( )
53+ . direction ( Direction :: Vertical )
54+ . constraints ( [ Constraint :: Percentage ( 100 ) ] )
55+ . split ( main[ 0 ] ) ;
56+ // When the window height is too small to show the preview window.
57+
58+ preview_and_commands[ 0 ]
59+ } else {
60+ let preview_and_commands = Layout :: default ( )
61+ . direction ( Direction :: Vertical )
62+ . constraints ( [ Constraint :: Percentage ( 70 ) , Constraint :: Percentage ( 30 ) ] )
63+ . split ( main[ 0 ] ) ;
64+
65+ // Render the preview window only when the window height is enough.
66+ render_preview_block ( model, f, preview_and_commands[ 0 ] ) ;
6467
65- let commands = Layout :: default ( )
68+ preview_and_commands[ 1 ]
69+ } ;
70+
71+ let commands_and_history = Layout :: default ( )
6672 . direction ( Direction :: Horizontal )
6773 . constraints ( [ Constraint :: Percentage ( 50 ) , Constraint :: Percentage ( 50 ) ] )
68- . split ( preview_and_commands[ 1 ] ) ;
69- render_commands_block ( model, f, commands[ 0 ] ) ;
70- render_history_block ( model, f, commands[ 1 ] ) ;
74+ . split ( commands) ;
7175
76+ render_commands_block ( model, f, commands_and_history[ 0 ] ) ;
77+ render_history_block ( model, f, commands_and_history[ 1 ] ) ;
7278 // Render additional arguments popup if needed.
7379 render_additional_arguments_popup ( model, f) ;
7480 }
7581}
7682
83+ const HEIGHT_THRESHOLD_TO_HIDE_PREVIEW_WINDOW : u16 = 20 ;
7784const FG_COLOR_SELECTED : ratatui:: style:: Color = Color :: Rgb ( 161 , 220 , 156 ) ;
7885const FG_COLOR_NOT_SELECTED : ratatui:: style:: Color = Color :: DarkGray ;
7986const BORDER_STYLE_SELECTED : ratatui:: widgets:: block:: BorderType = ratatui:: widgets:: BorderType :: Thick ;
@@ -315,6 +322,15 @@ fn render_history_block(model: &mut SelectCommandState, f: &mut Frame, chunk: ra
315322 ) ;
316323}
317324
325+ /// helper function to create a centered rect using up certain percentage of the available rect `r`
326+ fn popup_area ( area : Rect , x : u16 , y : u16 ) -> Rect {
327+ let vertical = Layout :: vertical ( [ Constraint :: Length ( y) ] ) . flex ( Flex :: Center ) ;
328+ let horizontal = Layout :: horizontal ( [ Constraint :: Percentage ( x) ] ) . flex ( Flex :: Center ) ;
329+ let [ area] = vertical. areas ( area) ;
330+ let [ area] = horizontal. areas ( area) ;
331+ area
332+ }
333+
318334fn render_additional_arguments_popup ( model : & mut SelectCommandState , f : & mut Frame ) {
319335 if model. additional_arguments_popup_state . is_none ( ) {
320336 return ;
0 commit comments