Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
cht committed Dec 8, 2021
1 parent d47372c commit 2fdfd96
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 30 deletions.
6 changes: 3 additions & 3 deletions src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ pub fn run_app(terminal: &mut Terminal<MyBackend>) -> 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();
Expand Down
28 changes: 15 additions & 13 deletions src/subscribe/appsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,47 +25,48 @@ pub struct AppSub {
pub(crate) input_mode: InputMode,
// History of recorded subs
// subs's names
pub subs: Vec<String>,
pub state: ListState,
pub subs: Vec<Vec<String>>,
pub subsindex : usize,
pub state: Vec<ListState>,
pub index_subscription: ListState,
pub index_settings: usize,
pub stateoflist: bool,
pub show_popup: bool,
// subscribes's information
pub informations: Vec<spider::Information>,
pub informations: Vec<Vec<spider::Information>>,
pub subscription: Vec<String>,
}
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
}
}
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() {
Expand Down Expand Up @@ -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(),
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/subscribe/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub(crate) fn ui<B: Backend>(f: &mut Frame<B>, app: &mut AppSub) {
.split(chunks[2]);

let subs: Vec<ListItem> = app
.subs
.subs[0]
.iter()
.enumerate()
.map(|(i, m)| {
Expand All @@ -106,10 +106,10 @@ pub(crate) fn ui<B: Backend>(f: &mut Frame<B>, 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<dyn Widget> = {
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<ListItem> = list
.iter()
.map(|infom| {
Expand Down
20 changes: 10 additions & 10 deletions src/subscribe/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ pub(crate) fn subscribe_state(app: &mut AppSub) -> io::Result<IFEXIT> {
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())
Expand Down Expand Up @@ -85,11 +85,11 @@ pub(crate) fn subscribe_state(app: &mut AppSub) -> io::Result<IFEXIT> {
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")
Expand Down Expand Up @@ -157,14 +157,14 @@ pub(crate) fn subscribe_state(app: &mut AppSub) -> io::Result<IFEXIT> {
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())
Expand Down

0 comments on commit 2fdfd96

Please sign in to comment.