@@ -38,6 +38,7 @@ enum InputMode {
3838struct App {
3939 /// Current value of the input box
4040 input : String ,
41+ v2ray_input : String ,
4142 /// Current input mode
4243 input_mode : InputMode ,
4344 /// History of recorded messages
@@ -87,6 +88,7 @@ impl Default for App {
8788 fn default ( ) -> App {
8889 App {
8990 input : String :: new ( ) ,
91+ v2ray_input : String :: new ( ) ,
9092 input_mode : InputMode :: Normal ,
9193 messages : Vec :: new ( ) ,
9294 state : ListState :: default ( ) ,
@@ -176,37 +178,7 @@ fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<(
176178 for alist in & list[ 0 ] {
177179 let information = spider:: Information :: new ( alist. to_string ( ) ) ;
178180 app. informations . push ( information. clone ( ) ) ;
179- storge. push_str (
180- format ! (
181- "{{
182- \" func\" :{},
183- \" url\" :\" {}\" ,
184- \" add\" :{},
185- \" aid\" :{},
186- \" host\" :{},
187- \" id\" :{},
188- \" net\" :{},
189- \" path\" :{},
190- \" port\" :{},
191- \" ps\" :{},
192- \" tls\" :{},
193- \" type\" :{}
194- }},\n " ,
195- information. clone( ) . func,
196- information. clone( ) . urls,
197- information. clone( ) . add,
198- information. clone( ) . aid,
199- information. clone( ) . host,
200- information. clone( ) . id,
201- information. clone( ) . net,
202- information. clone( ) . path,
203- information. clone( ) . port,
204- information. clone( ) . ps,
205- information. clone( ) . tls,
206- information. clone( ) . typpe
207- )
208- . as_str ( ) ,
209- ) ;
181+ storge. push_str ( information. get_the_json_node ( ) . as_str ( ) ) ;
210182 }
211183 }
212184 storge. pop ( ) ;
@@ -248,23 +220,26 @@ fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<(
248220 app. input_mode = InputMode :: Normal ;
249221 }
250222 }
251- InputMode :: Popup => {
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- _ => { }
223+ InputMode :: Popup => match key. code {
224+ KeyCode :: Char ( 'q' ) => {
225+ app. input_mode = InputMode :: Normal ;
226+ app. show_popup = false ;
261227 }
262- }
228+ KeyCode :: Char ( 'e' ) => {
229+ app. input_mode = InputMode :: PopupEdit ;
230+ }
231+ _ => { }
232+ } ,
263233 InputMode :: PopupEdit => {
264234 match key. code {
265- KeyCode :: Char ( 'q' ) => app. input_mode = InputMode :: Popup ,
235+ KeyCode :: Esc => app. input_mode = InputMode :: Popup ,
266236 // here todo
267- KeyCode :: Char ( 'e' ) => todo ! ( ) ,
237+ KeyCode :: Char ( c) => {
238+ app. v2ray_input . push ( c) ;
239+ }
240+ KeyCode :: Backspace => {
241+ app. v2ray_input . pop ( ) ;
242+ }
268243 _ => { }
269244 }
270245 }
@@ -333,14 +308,14 @@ fn ui<B: Backend>(f: &mut Frame<B>, app: &mut App) {
333308 } )
334309 . block ( Block :: default ( ) . borders ( Borders :: ALL ) . title ( "Input" ) ) ;
335310 f. render_widget ( input, chunks[ 1 ] ) ;
336- if let InputMode :: Editing = app. input_mode {
337- // Make the cursor visible and ask tui-rs to put it at the specified coordinates after rendering
338- f. set_cursor (
339- // Put cursor past the end of the input text
340- chunks[ 1 ] . x + app. input . width ( ) as u16 + 1 ,
341- // Move one line down, from the border to the input line
342- chunks[ 1 ] . y + 1 ,
343- )
311+ if let InputMode :: Editing = app. input_mode {
312+ // Make the cursor visible and ask tui-rs to put it at the specified coordinates after rendering
313+ f. set_cursor (
314+ // Put cursor past the end of the input text
315+ chunks[ 1 ] . x + app. input . width ( ) as u16 + 1 ,
316+ // Move one line down, from the border to the input line
317+ chunks[ 1 ] . y + 1 ,
318+ )
344319 //InputMode::Normal | InputMode::Select | InputMode::Popup =>
345320 // Hide the cursor. `Frame` does this by default, so we don't need to do anything here
346321 }
@@ -392,16 +367,27 @@ fn ui<B: Backend>(f: &mut Frame<B>, app: &mut App) {
392367
393368 if app. show_popup {
394369 //let block = Block::default().title("About port").borders(Borders::ALL);
395- let inputpop = Paragraph :: new ( app. input . as_ref ( ) )
370+ let inputpop = Paragraph :: new ( app. v2ray_input . as_ref ( ) )
396371 . style ( match app. input_mode {
397372 InputMode :: PopupEdit => Style :: default ( ) . fg ( Color :: Yellow ) ,
398373 _ => Style :: default ( ) ,
399374 } )
400- . block ( Block :: default ( ) . borders ( Borders :: ALL ) . title ( "Input " ) ) ;
375+ . block ( Block :: default ( ) . borders ( Borders :: ALL ) . title ( "Settings " ) ) ;
401376 //f.render_widget(input, chunks[1]);
402377 let area = centered_rect ( 60 , 20 , f. size ( ) ) ;
403378 f. render_widget ( Clear , area) ; //this clears out the background
404379 f. render_widget ( inputpop, area) ;
380+ if let InputMode :: PopupEdit = app. input_mode {
381+ // Make the cursor visible and ask tui-rs to put it at the specified coordinates after rendering
382+ f. set_cursor (
383+ // Put cursor past the end of the input text
384+ area. x + app. v2ray_input . width ( ) as u16 + 1 ,
385+ // Move one line down, from the border to the input line
386+ area. y + 1 ,
387+ )
388+ //InputMode::Normal | InputMode::Select | InputMode::Popup =>
389+ // Hide the cursor. `Frame` does this by default, so we don't need to do anything here
390+ }
405391 }
406392}
407393fn centered_rect ( percent_x : u16 , percent_y : u16 , r : Rect ) -> Rect {
0 commit comments