@@ -4,20 +4,24 @@ use crate::spider;
44use crate :: subscribe:: appsub:: AppSub ;
55use crate :: utils;
66use std:: io;
7- use tui:: { backend:: Backend , Terminal } ;
8-
7+ use std:: io:: Stdout ;
8+ use tui:: backend:: CrosstermBackend ;
9+ use tui:: Terminal ;
10+ #[ derive( Clone , Copy ) ]
911pub enum Page {
10- SubScribe ,
11- Information ,
12+ SubScribe = 0 ,
13+ Information = 1 ,
1214}
1315// 这个做成tab的选择入口
1416pub enum IFEXIT {
1517 Next ,
1618 Exit ,
1719 Change ( Page ) ,
1820}
21+
22+ pub type MyBackend = CrosstermBackend < Stdout > ;
1923//计划将它设置成一个入口
20- pub fn run_app < B : Backend > ( terminal : & mut Terminal < B > ) -> io:: Result < ( ) > {
24+ pub fn run_app ( terminal : & mut Terminal < MyBackend > ) -> io:: Result < ( ) > {
2125 let mut appsub = AppSub :: default ( ) ;
2226 let informations = utils:: start ( ) ;
2327 if !informations. is_empty ( ) {
@@ -29,21 +33,16 @@ pub fn run_app<B: Backend>(terminal: &mut Terminal<B>) -> io::Result<()> {
2933 appsub. state . select ( Some ( 0 ) ) ;
3034 appsub. informations = informations;
3135 }
32- let mut appbar = AppBar :: new ( ) ;
36+ let appbar = AppBar :: new ( ) ;
3337 appsub. settings_input [ 0 ] = utils:: start_v2core ( ) ;
3438 let mut local_page = Page :: SubScribe ;
39+ let mut pages: Vec < Box < dyn App > > = vec ! [ Box :: new( appsub) , Box :: new( appbar) ] ;
40+
3541 loop {
36- match local_page {
37- Page :: SubScribe => match appsub. run_app_local ( terminal) ? {
38- IFEXIT :: Exit => return Ok ( ( ) ) ,
39- IFEXIT :: Change ( e) => local_page = e,
40- IFEXIT :: Next => { }
41- } ,
42- Page :: Information => match appbar. run_app_local ( terminal) ? {
43- IFEXIT :: Exit => return Ok ( ( ) ) ,
44- IFEXIT :: Change ( e) => local_page = e,
45- IFEXIT :: Next => { }
46- } ,
42+ match pages[ local_page as usize ] . run_app_local ( terminal) ? {
43+ IFEXIT :: Exit => return Ok ( ( ) ) ,
44+ IFEXIT :: Change ( e) => local_page = e,
45+ IFEXIT :: Next => { }
4746 }
4847 }
4948}
0 commit comments