diff --git a/src/state.rs b/src/state.rs index b57b4d4..95b5f79 100644 --- a/src/state.rs +++ b/src/state.rs @@ -25,13 +25,13 @@ pub fn run_app(terminal: &mut Terminal) -> io::Result<()> { let mut appsub = AppSub::default(); let informations = utils::start(); if !informations.is_empty() { - appsub.subs = informations + appsub.subs[0] = informations .iter() .map(|amessage| spider::remove_quotation(amessage.ps.clone())) .collect(); appsub.stateoflist = true; - appsub.state.select(Some(0)); - appsub.informations = informations; + appsub.state[0].select(Some(0)); + appsub.informations[0] = informations; } appsub.subscription = utils::get_subs(); appsub.settings_input[0] = utils::start_v2core(); diff --git a/src/subscribe/appsub.rs b/src/subscribe/appsub.rs index 208fa0f..8ab851b 100644 --- a/src/subscribe/appsub.rs +++ b/src/subscribe/appsub.rs @@ -25,21 +25,22 @@ pub struct AppSub { pub(crate) input_mode: InputMode, // History of recorded subs // subs's names - pub subs: Vec, - pub state: ListState, + pub subs: Vec>, + pub subsindex : usize, + pub state: Vec, pub index_subscription: ListState, pub index_settings: usize, pub stateoflist: bool, pub show_popup: bool, // subscribes's information - pub informations: Vec, + pub informations: Vec>, pub subscription: Vec, } impl AppSub { pub fn next(&mut self) { - let i = match self.state.selected() { + let i = match self.state[self.subsindex].selected() { Some(i) => { - if i >= self.subs.len() - 1 { + if i >= self.subs[self.subsindex].len() - 1 { 0 } else { i + 1 @@ -47,25 +48,25 @@ impl AppSub { } None => 0, }; - self.state.select(Some(i)); + self.state[self.subsindex].select(Some(i)); } pub fn previous(&mut self) { - let i = match self.state.selected() { + let i = match self.state[self.subsindex].selected() { Some(i) => { if i == 0 { - self.subs.len() - 1 + self.subs[self.subsindex].len() - 1 } else { i - 1 } } None => 0, }; - self.state.select(Some(i)); + self.state[self.subsindex].select(Some(i)); } pub fn unselect(&mut self) { - self.state.select(None); + self.state[self.subsindex].select(None); } pub fn next_sub(&mut self) { let i = match self.index_subscription.selected() { @@ -113,13 +114,14 @@ impl Default for AppSub { input: String::new(), settings_input: vec![String::new(), String::new()], input_mode: InputMode::Normal, - subs: Vec::new(), - state: ListState::default(), + subs: vec![vec![]], + subsindex: 0, + state: vec![ListState::default()], index_subscription: ListState::default(), index_settings: 0, stateoflist: false, show_popup: false, - informations: Vec::new(), + informations: vec![vec![]], subscription: Vec::new(), } } diff --git a/src/subscribe/render.rs b/src/subscribe/render.rs index 6667d51..d23e2b0 100644 --- a/src/subscribe/render.rs +++ b/src/subscribe/render.rs @@ -89,7 +89,7 @@ pub(crate) fn ui(f: &mut Frame, app: &mut AppSub) { .split(chunks[2]); let subs: Vec = app - .subs + .subs[0] .iter() .enumerate() .map(|(i, m)| { @@ -106,10 +106,10 @@ pub(crate) fn ui(f: &mut Frame, app: &mut AppSub) { ) .highlight_symbol(">> "); // popup wiget - f.render_stateful_widget(subs, bottom_chunks[0], &mut app.state); + f.render_stateful_widget(subs, bottom_chunks[0], &mut app.state[app.subsindex]); //let block : Box = { - if let Some(a) = app.state.selected() { - let list = app.informations[a].information_to_list(); + if let Some(a) = app.state[app.subsindex].selected() { + let list = app.informations[app.subsindex][a].information_to_list(); let messages: Vec = list .iter() .map(|infom| { diff --git a/src/subscribe/state.rs b/src/subscribe/state.rs index 8a04437..f2f76ce 100644 --- a/src/subscribe/state.rs +++ b/src/subscribe/state.rs @@ -39,14 +39,14 @@ pub(crate) fn subscribe_state(app: &mut AppSub) -> io::Result { if !list[0].is_empty() { //app.subs = list[0].clone(); app.stateoflist = true; - app.state.select(Some(0)); + app.state[app.subsindex].select(Some(0)); for alist in &list[0] { let information = spider::Information::new(alist.to_string()); - app.informations.push(information.clone()); + app.informations[0].push(information.clone()); storge.push_str(information.get_the_json_node().as_str()); } - app.subs = app - .informations + app.subs[0] = app + .informations[0] .iter() .map(|ainformation| { spider::remove_quotation(ainformation.ps.clone()) @@ -85,11 +85,11 @@ pub(crate) fn subscribe_state(app: &mut AppSub) -> io::Result { app.input_mode = InputMode::Normal; } KeyCode::F(5) => { - if let Some(index) = app.state.selected() { + if let Some(index) = app.state[app.subsindex].selected() { let home = env::var("HOME").unwrap(); utils::create_json_file( utils::Save::Running, - app.informations[index].clone().running_json(), + app.informations[app.subsindex][index].clone().running_json(), ) .unwrap_or_else(|err| panic!("err {}", err)); Command::new("pkill") @@ -157,14 +157,14 @@ pub(crate) fn subscribe_state(app: &mut AppSub) -> io::Result { if !list.is_empty() && !list[0].is_empty() { //app.subs = list[0].clone(); app.stateoflist = true; - app.state.select(Some(0)); + app.state[app.subsindex].select(Some(0)); for alist in &list[0] { let information = spider::Information::new(alist.to_string()); - app.informations.push(information.clone()); + app.informations[0].push(information.clone()); storge.push_str(information.get_the_json_node().as_str()); } - app.subs = app - .informations + app.subs[0] = app + .informations[0] .iter() .map(|ainformation| { spider::remove_quotation(ainformation.ps.clone())