Skip to content

Commit 2fdfd96

Browse files
author
cht
committed
temp
1 parent d47372c commit 2fdfd96

4 files changed

Lines changed: 32 additions & 30 deletions

File tree

src/state.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ pub fn run_app(terminal: &mut Terminal<MyBackend>) -> io::Result<()> {
2525
let mut appsub = AppSub::default();
2626
let informations = utils::start();
2727
if !informations.is_empty() {
28-
appsub.subs = informations
28+
appsub.subs[0] = informations
2929
.iter()
3030
.map(|amessage| spider::remove_quotation(amessage.ps.clone()))
3131
.collect();
3232
appsub.stateoflist = true;
33-
appsub.state.select(Some(0));
34-
appsub.informations = informations;
33+
appsub.state[0].select(Some(0));
34+
appsub.informations[0] = informations;
3535
}
3636
appsub.subscription = utils::get_subs();
3737
appsub.settings_input[0] = utils::start_v2core();

src/subscribe/appsub.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,47 +25,48 @@ pub struct AppSub {
2525
pub(crate) input_mode: InputMode,
2626
// History of recorded subs
2727
// subs's names
28-
pub subs: Vec<String>,
29-
pub state: ListState,
28+
pub subs: Vec<Vec<String>>,
29+
pub subsindex : usize,
30+
pub state: Vec<ListState>,
3031
pub index_subscription: ListState,
3132
pub index_settings: usize,
3233
pub stateoflist: bool,
3334
pub show_popup: bool,
3435
// subscribes's information
35-
pub informations: Vec<spider::Information>,
36+
pub informations: Vec<Vec<spider::Information>>,
3637
pub subscription: Vec<String>,
3738
}
3839
impl AppSub {
3940
pub fn next(&mut self) {
40-
let i = match self.state.selected() {
41+
let i = match self.state[self.subsindex].selected() {
4142
Some(i) => {
42-
if i >= self.subs.len() - 1 {
43+
if i >= self.subs[self.subsindex].len() - 1 {
4344
0
4445
} else {
4546
i + 1
4647
}
4748
}
4849
None => 0,
4950
};
50-
self.state.select(Some(i));
51+
self.state[self.subsindex].select(Some(i));
5152
}
5253

5354
pub fn previous(&mut self) {
54-
let i = match self.state.selected() {
55+
let i = match self.state[self.subsindex].selected() {
5556
Some(i) => {
5657
if i == 0 {
57-
self.subs.len() - 1
58+
self.subs[self.subsindex].len() - 1
5859
} else {
5960
i - 1
6061
}
6162
}
6263
None => 0,
6364
};
64-
self.state.select(Some(i));
65+
self.state[self.subsindex].select(Some(i));
6566
}
6667

6768
pub fn unselect(&mut self) {
68-
self.state.select(None);
69+
self.state[self.subsindex].select(None);
6970
}
7071
pub fn next_sub(&mut self) {
7172
let i = match self.index_subscription.selected() {
@@ -113,13 +114,14 @@ impl Default for AppSub {
113114
input: String::new(),
114115
settings_input: vec![String::new(), String::new()],
115116
input_mode: InputMode::Normal,
116-
subs: Vec::new(),
117-
state: ListState::default(),
117+
subs: vec![vec![]],
118+
subsindex: 0,
119+
state: vec![ListState::default()],
118120
index_subscription: ListState::default(),
119121
index_settings: 0,
120122
stateoflist: false,
121123
show_popup: false,
122-
informations: Vec::new(),
124+
informations: vec![vec![]],
123125
subscription: Vec::new(),
124126
}
125127
}

src/subscribe/render.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ pub(crate) fn ui<B: Backend>(f: &mut Frame<B>, app: &mut AppSub) {
8989
.split(chunks[2]);
9090

9191
let subs: Vec<ListItem> = app
92-
.subs
92+
.subs[0]
9393
.iter()
9494
.enumerate()
9595
.map(|(i, m)| {
@@ -106,10 +106,10 @@ pub(crate) fn ui<B: Backend>(f: &mut Frame<B>, app: &mut AppSub) {
106106
)
107107
.highlight_symbol(">> ");
108108
// popup wiget
109-
f.render_stateful_widget(subs, bottom_chunks[0], &mut app.state);
109+
f.render_stateful_widget(subs, bottom_chunks[0], &mut app.state[app.subsindex]);
110110
//let block : Box<dyn Widget> = {
111-
if let Some(a) = app.state.selected() {
112-
let list = app.informations[a].information_to_list();
111+
if let Some(a) = app.state[app.subsindex].selected() {
112+
let list = app.informations[app.subsindex][a].information_to_list();
113113
let messages: Vec<ListItem> = list
114114
.iter()
115115
.map(|infom| {

src/subscribe/state.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ pub(crate) fn subscribe_state(app: &mut AppSub) -> io::Result<IFEXIT> {
3939
if !list[0].is_empty() {
4040
//app.subs = list[0].clone();
4141
app.stateoflist = true;
42-
app.state.select(Some(0));
42+
app.state[app.subsindex].select(Some(0));
4343
for alist in &list[0] {
4444
let information = spider::Information::new(alist.to_string());
45-
app.informations.push(information.clone());
45+
app.informations[0].push(information.clone());
4646
storge.push_str(information.get_the_json_node().as_str());
4747
}
48-
app.subs = app
49-
.informations
48+
app.subs[0] = app
49+
.informations[0]
5050
.iter()
5151
.map(|ainformation| {
5252
spider::remove_quotation(ainformation.ps.clone())
@@ -85,11 +85,11 @@ pub(crate) fn subscribe_state(app: &mut AppSub) -> io::Result<IFEXIT> {
8585
app.input_mode = InputMode::Normal;
8686
}
8787
KeyCode::F(5) => {
88-
if let Some(index) = app.state.selected() {
88+
if let Some(index) = app.state[app.subsindex].selected() {
8989
let home = env::var("HOME").unwrap();
9090
utils::create_json_file(
9191
utils::Save::Running,
92-
app.informations[index].clone().running_json(),
92+
app.informations[app.subsindex][index].clone().running_json(),
9393
)
9494
.unwrap_or_else(|err| panic!("err {}", err));
9595
Command::new("pkill")
@@ -157,14 +157,14 @@ pub(crate) fn subscribe_state(app: &mut AppSub) -> io::Result<IFEXIT> {
157157
if !list.is_empty() && !list[0].is_empty() {
158158
//app.subs = list[0].clone();
159159
app.stateoflist = true;
160-
app.state.select(Some(0));
160+
app.state[app.subsindex].select(Some(0));
161161
for alist in &list[0] {
162162
let information = spider::Information::new(alist.to_string());
163-
app.informations.push(information.clone());
163+
app.informations[0].push(information.clone());
164164
storge.push_str(information.get_the_json_node().as_str());
165165
}
166-
app.subs = app
167-
.informations
166+
app.subs[0] = app
167+
.informations[0]
168168
.iter()
169169
.map(|ainformation| {
170170
spider::remove_quotation(ainformation.ps.clone())

0 commit comments

Comments
 (0)