Skip to content

Commit 9de47bb

Browse files
author
cht
committed
cargo fmt
1 parent 309b35e commit 9de47bb

5 files changed

Lines changed: 40 additions & 32 deletions

File tree

src/app.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::state::{MyBackend, IFEXIT};
2+
use async_trait::async_trait;
23
use std::io;
34
use tui::Terminal;
4-
use async_trait::async_trait;
55
#[async_trait]
66
pub trait App {
77
async fn run_app_local(&mut self, terminal: &mut Terminal<MyBackend>) -> io::Result<IFEXIT>;

src/state.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use crate::utils;
66
use std::io;
77
use std::io::Stdout;
88
use tui::backend::CrosstermBackend;
9-
use tui::Terminal;
109
use tui::widgets::ListState;
10+
use tui::Terminal;
1111
#[derive(Clone, Copy)]
1212
pub enum Page {
1313
SubScribe = 0,
@@ -28,14 +28,16 @@ pub async fn run_app(terminal: &mut Terminal<MyBackend>) -> io::Result<()> {
2828
if !informations.is_empty() {
2929
appsub.subs = informations
3030
.iter()
31-
.map(|ainformation| ainformation
32-
.iter()
33-
.map(|message| spider::remove_quotation(message.ps.clone()))
34-
.collect())
31+
.map(|ainformation| {
32+
ainformation
33+
.iter()
34+
.map(|message| spider::remove_quotation(message.ps.clone()))
35+
.collect()
36+
})
3537
.collect();
3638
appsub.stateoflist = true;
3739
let len = informations.len();
38-
appsub.state = vec![ListState::default();len];
40+
appsub.state = vec![ListState::default(); len];
3941
//appsub.state[0].select(Some(0));
4042
appsub.informations = informations.clone();
4143
}

src/subscribe/appsub.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub struct AppSub {
2626
// History of recorded subs
2727
// subs's names
2828
pub subs: Vec<Vec<String>>,
29-
pub subsindex : usize,
29+
pub subsindex: usize,
3030
pub state: Vec<ListState>,
3131
pub index_subscription: ListState,
3232
pub index_settings: usize,
@@ -64,18 +64,18 @@ impl AppSub {
6464
};
6565
self.state[self.subsindex].select(Some(i));
6666
}
67-
pub fn left(&mut self){
67+
pub fn left(&mut self) {
6868
if self.subsindex == 0 {
69-
self.subsindex = self.state.len()-1;
69+
self.subsindex = self.state.len() - 1;
7070
} else {
71-
self.subsindex -=1;
71+
self.subsindex -= 1;
7272
}
7373
}
74-
pub fn right(&mut self){
75-
if self.subsindex >= self.state.len() -1 {
74+
pub fn right(&mut self) {
75+
if self.subsindex >= self.state.len() - 1 {
7676
self.subsindex = 0;
7777
} else {
78-
self.subsindex +=1;
78+
self.subsindex += 1;
7979
}
8080
}
8181
pub fn unselect(&mut self) {

src/subscribe/render.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ pub(crate) fn ui<B: Backend>(f: &mut Frame<B>, app: &mut AppSub) {
8686
.constraints([Constraint::Percentage(40), Constraint::Percentage(60)].as_ref())
8787
.split(chunks[2]);
8888

89-
let subs: Vec<ListItem> = app
90-
.subs[app.subsindex]
89+
let subs: Vec<ListItem> = app.subs[app.subsindex]
9190
.iter()
9291
.enumerate()
9392
.map(|(i, m)| {
@@ -96,7 +95,11 @@ pub(crate) fn ui<B: Backend>(f: &mut Frame<B>, app: &mut AppSub) {
9695
})
9796
.collect();
9897
let subs = List::new(subs)
99-
.block(Block::default().borders(Borders::ALL).title(format!("Subscribe {}",app.subsindex)))
98+
.block(
99+
Block::default()
100+
.borders(Borders::ALL)
101+
.title(format!("Subscribe {}", app.subsindex)),
102+
)
100103
.highlight_style(
101104
Style::default()
102105
.bg(Color::LightGreen)
@@ -119,7 +122,9 @@ pub(crate) fn ui<B: Backend>(f: &mut Frame<B>, app: &mut AppSub) {
119122
List::new(messages).block(Block::default().borders(Borders::ALL).title("Informations"));
120123
f.render_widget(block, bottom_chunks[1]);
121124
} else {
122-
let block = Block::default().title("Informations None").borders(Borders::ALL);
125+
let block = Block::default()
126+
.title("Informations None")
127+
.borders(Borders::ALL);
123128
f.render_widget(block, bottom_chunks[1]);
124129
}
125130
//};

src/subscribe/state.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ pub(crate) async fn subscribe_state(app: &mut AppSub) -> io::Result<IFEXIT> {
6161
let home = env::var("HOME").unwrap();
6262
utils::create_json_file(
6363
utils::Save::Running,
64-
app.informations[app.subsindex][index].clone().running_json(),
64+
app.informations[app.subsindex][index]
65+
.clone()
66+
.running_json(),
6567
)
6668
.unwrap_or_else(|err| panic!("err {}", err));
6769
Command::new("pkill")
@@ -123,12 +125,12 @@ pub(crate) async fn subscribe_state(app: &mut AppSub) -> io::Result<IFEXIT> {
123125
// .collect();
124126
let get_list = spider::get_the_key(app.subscription.clone()).await;
125127
if let Ok(list) = get_list {
126-
if !list.is_empty(){
128+
if !list.is_empty() {
127129
let mut storge: String = "[\n\n".to_string();
128-
let mut subs : Vec<Vec<String>> =Vec::new();
129-
let mut information :Vec<Vec<spider::Information>> = Vec::new();
130-
let mut state: Vec<ListState>= Vec::new();
131-
for lista in list {
130+
let mut subs: Vec<Vec<String>> = Vec::new();
131+
let mut information: Vec<Vec<spider::Information>> = Vec::new();
132+
let mut state: Vec<ListState> = Vec::new();
133+
for lista in list {
132134
let mut ainformation: Vec<spider::Information> = Vec::new();
133135
//let mut asub: Vec<String> = Vec::new();
134136
storge.push_str("[\n\n");
@@ -137,19 +139,19 @@ pub(crate) async fn subscribe_state(app: &mut AppSub) -> io::Result<IFEXIT> {
137139
let inform = spider::Information::new(alist.to_string());
138140
ainformation.push(inform.clone());
139141
storge.push_str(&inform.get_the_json_node());
140-
141142
}
142143
storge.pop();
143144
storge.pop();
144145
storge.push_str("\n ],");
145146
}
146147
state.push(ListState::default());
147-
subs.push(ainformation
148-
.iter()
149-
.map(|ainfor| spider::remove_quotation(ainfor.ps.clone()))
150-
.collect());
148+
subs.push(
149+
ainformation
150+
.iter()
151+
.map(|ainfor| spider::remove_quotation(ainfor.ps.clone()))
152+
.collect(),
153+
);
151154
information.push(ainformation);
152-
153155
}
154156
app.state = state;
155157
app.subs = subs;
@@ -160,8 +162,7 @@ pub(crate) async fn subscribe_state(app: &mut AppSub) -> io::Result<IFEXIT> {
160162
.unwrap_or_else(|err| panic!("err {}", err));
161163
app.subsindex = 0;
162164
app.state[0].select(Some(0));
163-
app.stateoflist=true;
164-
165+
app.stateoflist = true;
165166
}
166167
}
167168
}

0 commit comments

Comments
 (0)