@@ -31,6 +31,7 @@ enum InputMode {
3131 Editing ,
3232 Select ,
3333 Popup ,
34+ PopupEdit ,
3435}
3536
3637/// App holds the state of the application
@@ -152,6 +153,11 @@ fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<(
152153 KeyCode :: Char ( 'q' ) => {
153154 return Ok ( ( ) ) ;
154155 }
156+ KeyCode :: Char ( 'h' ) => {
157+ //app.input = app.index.as_ref().unwrap().to_string();
158+ app. show_popup = true ;
159+ app. input_mode = InputMode :: Popup ;
160+ }
155161 _ => { }
156162 } ,
157163 InputMode :: Editing => match key. code {
@@ -207,7 +213,8 @@ fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<(
207213 storge. pop ( ) ;
208214 storge. push ( '\n' ) ;
209215 storge. push ( ']' ) ;
210- if let Err ( err) = utils:: create_json_file ( storge) {
216+ if let Err ( err) = utils:: create_json_file ( utils:: Save :: Storage , storge)
217+ {
211218 panic ! ( "err {}" , err) ;
212219 } ;
213220 }
@@ -234,21 +241,29 @@ fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<(
234241 KeyCode :: Esc => {
235242 app. input_mode = InputMode :: Normal ;
236243 }
237- KeyCode :: Enter => {
238- //app.input = app.index.as_ref().unwrap().to_string();
239- app. show_popup = true ;
240- app. input_mode = InputMode :: Popup ;
241- }
244+
242245 _ => { }
243246 }
244247 } else {
245248 app. input_mode = InputMode :: Normal ;
246249 }
247250 }
248251 InputMode :: Popup => {
249- if let KeyCode :: Char ( 'q' ) = key. code {
250- app. input_mode = InputMode :: Select ;
251- app. show_popup = false ;
252+ match key. code {
253+ KeyCode :: Char ( 'q' ) => {
254+ app. input_mode = InputMode :: Normal ;
255+ app. show_popup = false ;
256+ } ,
257+ KeyCode :: Char ( 'e' ) => {
258+ app. input_mode = InputMode :: PopupEdit ;
259+ } ,
260+ _ => { }
261+ }
262+ }
263+ InputMode :: PopupEdit => {
264+ match key. code {
265+ KeyCode :: Char ( 'q' ) => app. input_mode = InputMode :: Popup ,
266+ _ => { }
252267 }
253268 }
254269 }
@@ -271,7 +286,7 @@ fn ui<B: Backend>(f: &mut Frame<B>, app: &mut App) {
271286 . split ( f. size ( ) ) ;
272287
273288 let ( msg, style) = match app. input_mode {
274- InputMode :: Normal | InputMode :: Popup => (
289+ InputMode :: Normal | InputMode :: Popup | InputMode :: PopupEdit => (
275290 vec ! [
276291 Span :: raw( "Press " ) ,
277292 Span :: styled( "q" , Style :: default ( ) . add_modifier( Modifier :: BOLD ) ) ,
@@ -311,16 +326,12 @@ fn ui<B: Backend>(f: &mut Frame<B>, app: &mut App) {
311326
312327 let input = Paragraph :: new ( app. input . as_ref ( ) )
313328 . style ( match app. input_mode {
314- InputMode :: Normal | InputMode :: Select | InputMode :: Popup => Style :: default ( ) ,
315329 InputMode :: Editing => Style :: default ( ) . fg ( Color :: Yellow ) ,
330+ _ => Style :: default ( ) ,
316331 } )
317332 . block ( Block :: default ( ) . borders ( Borders :: ALL ) . title ( "Input" ) ) ;
318333 f. render_widget ( input, chunks[ 1 ] ) ;
319334 match app. input_mode {
320- InputMode :: Normal | InputMode :: Select | InputMode :: Popup =>
321- // Hide the cursor. `Frame` does this by default, so we don't need to do anything here
322- { }
323-
324335 InputMode :: Editing => {
325336 // Make the cursor visible and ask tui-rs to put it at the specified coordinates after rendering
326337 f. set_cursor (
@@ -330,6 +341,9 @@ fn ui<B: Backend>(f: &mut Frame<B>, app: &mut App) {
330341 chunks[ 1 ] . y + 1 ,
331342 )
332343 }
344+ //InputMode::Normal | InputMode::Select | InputMode::Popup =>
345+ // Hide the cursor. `Frame` does this by default, so we don't need to do anything here
346+ _ => { }
333347 }
334348
335349 // Bottom two inner blocks
@@ -378,10 +392,17 @@ fn ui<B: Backend>(f: &mut Frame<B>, app: &mut App) {
378392 //f.render_widget(*block, bottom_chunks[0]);
379393
380394 if app. show_popup {
381- let block = Block :: default ( ) . title ( "About port" ) . borders ( Borders :: ALL ) ;
395+ //let block = Block::default().title("About port").borders(Borders::ALL);
396+ let inputpop = Paragraph :: new ( app. input . as_ref ( ) )
397+ . style ( match app. input_mode {
398+ InputMode :: PopupEdit => Style :: default ( ) . fg ( Color :: Yellow ) ,
399+ _ => Style :: default ( ) ,
400+ } )
401+ . block ( Block :: default ( ) . borders ( Borders :: ALL ) . title ( "Input" ) ) ;
402+ //f.render_widget(input, chunks[1]);
382403 let area = centered_rect ( 60 , 20 , f. size ( ) ) ;
383404 f. render_widget ( Clear , area) ; //this clears out the background
384- f. render_widget ( block , area) ;
405+ f. render_widget ( inputpop , area) ;
385406 }
386407}
387408fn centered_rect ( percent_x : u16 , percent_y : u16 , r : Rect ) -> Rect {
0 commit comments