11use crate :: ui:: app:: App ;
2- use ratatui:: { prelude:: * , text :: ToText , widgets:: * } ;
2+ use ratatui:: { prelude:: * , widgets:: * } ;
33
44pub fn render_ui ( f : & mut Frame , app : & mut App ) {
55 let chunks = Layout :: default ( )
@@ -97,47 +97,12 @@ pub fn render_ui(f: &mut Frame, app: &mut App) {
9797 . block ( Block :: default ( ) . borders ( Borders :: ALL ) . title ( "Logs" ) ) ;
9898 f. render_widget ( logs, chunks[ 1 ] ) ;
9999
100- let help_text = "Shortcuts: [Q] Quit | Use 'firebee add' command to add rules " ;
100+ let help_text = "[Q] Quit | Manage rules via CLI: firebee add/delete/get " ;
101101 let help = Paragraph :: new ( help_text)
102102 . style ( Style :: default ( ) . fg ( Color :: Gray ) )
103103 . alignment ( ratatui:: layout:: Alignment :: Center )
104104 . block ( Block :: default ( ) . borders ( Borders :: ALL ) ) ;
105105 f. render_widget ( help, chunks[ 2 ] ) ;
106-
107- if app. input_mode {
108- let popup = Paragraph :: new ( app. input . to_text ( ) ) . block (
109- Block :: default ( )
110- . borders ( Borders :: ALL )
111- . title ( "Enter IP (e.g., 192.168.1.1)" ) ,
112- ) ;
113- let area = centered_rect ( 40 , 20 , f. area ( ) ) ;
114- f. render_widget ( Clear , area) ;
115- f. render_widget ( popup, area) ;
116- }
117-
118- if app. confirm_unload {
119- let warning_text = [
120- "WARNING: This will unload the XDP firewall program!" ,
121- "" ,
122- "Are you sure you want to continue?" ,
123- "" ,
124- "Press Y to confirm, N or ESC to cancel" ,
125- ] ;
126-
127- let popup = Paragraph :: new ( warning_text. join ( "\n " ) )
128- . block (
129- Block :: default ( )
130- . borders ( Borders :: ALL )
131- . title ( "Confirm Unload" )
132- . style ( Style :: default ( ) . fg ( Color :: Red ) ) ,
133- )
134- . alignment ( ratatui:: layout:: Alignment :: Center )
135- . wrap ( Wrap { trim : true } ) ;
136-
137- let area = centered_rect ( 60 , 40 , f. area ( ) ) ;
138- f. render_widget ( Clear , area) ;
139- f. render_widget ( popup, area) ;
140- }
141106}
142107
143108fn format_number ( n : u64 ) -> String {
@@ -164,26 +129,6 @@ fn format_bytes(bytes: u64) -> String {
164129 }
165130}
166131
167- fn centered_rect ( percent_x : u16 , percent_y : u16 , r : Rect ) -> Rect {
168- let popup_layout = Layout :: default ( )
169- . direction ( Direction :: Vertical )
170- . constraints ( [
171- Constraint :: Percentage ( ( 100 - percent_y) / 2 ) ,
172- Constraint :: Percentage ( percent_y) ,
173- Constraint :: Percentage ( ( 100 - percent_y) / 2 ) ,
174- ] )
175- . split ( r) ;
176-
177- Layout :: default ( )
178- . direction ( Direction :: Horizontal )
179- . constraints ( [
180- Constraint :: Percentage ( ( 100 - percent_x) / 2 ) ,
181- Constraint :: Percentage ( percent_x) ,
182- Constraint :: Percentage ( ( 100 - percent_x) / 2 ) ,
183- ] )
184- . split ( popup_layout[ 1 ] ) [ 1 ]
185- }
186-
187132#[ cfg( test) ]
188133mod tests {
189134 use super :: * ;
0 commit comments