Recount-TUI/src/app.rs

31 lines
648 B
Rust
Raw Normal View History

2023-05-28 22:18:30 -07:00
2023-05-31 18:00:17 -07:00
pub type AppResult<T> = std::result::Result<T, Box<dyn std::error::Error>>;
2023-05-28 22:18:30 -07:00
pub struct App<'a> {
pub running: bool,
2023-05-31 18:00:17 -07:00
pub tabs: Vec<&'a str>,
pub tab_index: usize,
2023-05-28 22:18:30 -07:00
}
impl<'a> App<'a> {
2023-05-31 18:00:17 -07:00
pub fn new() -> App<'a> {
App {
running: true,
2023-05-28 22:18:30 -07:00
2023-05-31 18:00:17 -07:00
tabs: vec!["Tab1", "Tab2", "Tab3"],
tab_index: 0,
}
2023-05-28 22:18:30 -07:00
}
pub fn next_tab(&mut self) {
2023-05-31 18:00:17 -07:00
self.tab_index = (self.tab_index + 1) % self.tabs.len();
2023-05-28 22:18:30 -07:00
}
pub fn prev_tab(&mut self) {
2023-05-31 18:00:17 -07:00
if self.tab_index > 0 {
self.tab_index -= 1;
2023-05-28 22:18:30 -07:00
} else {
2023-05-31 18:00:17 -07:00
self.tab_index = self.tabs.len() - 1;
2023-05-28 22:18:30 -07:00
}
2023-05-31 18:00:17 -07:00
}}