Skip to content

Commit a0be5e1

Browse files
author
cht
committed
move state and rander to annother file
1 parent d5086d3 commit a0be5e1

3 files changed

Lines changed: 535 additions & 521 deletions

File tree

src/app.rs

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
use tui::widgets::ListState;
2+
use crate::spider;
3+
pub enum InputMode {
4+
Normal,
5+
Editing,
6+
Select,
7+
Popup,
8+
PopupEdit,
9+
SubscriptView,
10+
}
11+
12+
/// App holds the state of the application
13+
pub struct App {
14+
/// Current value of the input box
15+
pub input: String,
16+
pub settings_input: Vec<String>,
17+
/// Current input mode
18+
pub input_mode: InputMode,
19+
/// History of recorded messages
20+
pub messages: Vec<String>,
21+
pub state: ListState,
22+
pub index_subscription: ListState,
23+
pub index_settings: usize,
24+
pub stateoflist: bool,
25+
pub show_popup: bool,
26+
pub informations: Vec<spider::Information>,
27+
pub subscription : Vec<String>,
28+
}
29+
impl App {
30+
pub fn next(&mut self) {
31+
let i = match self.state.selected() {
32+
Some(i) => {
33+
if i >= self.messages.len() - 1 {
34+
0
35+
} else {
36+
i + 1
37+
}
38+
}
39+
None => 0,
40+
};
41+
self.state.select(Some(i));
42+
}
43+
44+
pub fn previous(&mut self) {
45+
let i = match self.state.selected() {
46+
Some(i) => {
47+
if i == 0 {
48+
self.messages.len() - 1
49+
} else {
50+
i - 1
51+
}
52+
}
53+
None => 0,
54+
};
55+
self.state.select(Some(i));
56+
}
57+
58+
pub fn unselect(&mut self) {
59+
self.state.select(None);
60+
}
61+
pub fn next_sub(&mut self) {
62+
let i = match self.index_subscription.selected() {
63+
Some(i) => {
64+
if i >= self.subscription.len() - 1 {
65+
0
66+
} else {
67+
i + 1
68+
}
69+
}
70+
None => 0,
71+
};
72+
self.index_subscription.select(Some(i));
73+
//self.index = Some(i);
74+
}
75+
76+
pub fn previous_sub(&mut self) {
77+
let i = match self.index_subscription.selected() {
78+
Some(i) => {
79+
if i == 0 {
80+
self.subscription.len() - 1
81+
} else {
82+
i - 1
83+
}
84+
}
85+
None => 0,
86+
};
87+
self.index_subscription.select(Some(i));
88+
//self.index = Some(i);
89+
}
90+
91+
pub fn unselect_sub(&mut self) {
92+
self.index_subscription.select(None);
93+
}
94+
}
95+
impl Default for App {
96+
fn default() -> App {
97+
App {
98+
input: String::new(),
99+
settings_input: vec![String::new(), String::new()],
100+
input_mode: InputMode::Normal,
101+
messages: Vec::new(),
102+
state: ListState::default(),
103+
index_subscription: ListState::default(),
104+
index_settings: 0,
105+
stateoflist: false,
106+
show_popup: false,
107+
informations: Vec::new(),
108+
subscription: Vec::new(),
109+
}
110+
}
111+
}
112+

0 commit comments

Comments
 (0)