Skip to content

Commit 4487a1c

Browse files
wip: add boilerplate code for new tab
1 parent 17b628f commit 4487a1c

File tree

5 files changed

+103
-1
lines changed

5 files changed

+103
-1
lines changed

.config/config.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
[keybindings.TimeTracking]
2+
3+
# App
4+
"<q>" = "Quit"
5+
"<Ctrl-c>" = "Quit"
6+
"<Ctrl-z>" = "Suspend"
7+
"<?>" = "Help"
8+
# Tabs
9+
"<Shift-Right>" = "TabRight"
10+
"<Shift-l>" = "TabRight"
11+
"<Shift-Left>" = "TabLeft"
12+
"<shift-h>" = "TabLeft"
13+
14+
115
[keybindings.Explorer]
216
# App
317
"<q>" = "Quit"

src/app.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ use crate::{
99
action::Action,
1010
cli::{Cli, Commands},
1111
components::{
12-
explorer_tab::ExplorerTab, filter_tab::FilterTab, fps::FpsCounter, home::Home, Component,
12+
explorer_tab::ExplorerTab, filter_tab::FilterTab, fps::FpsCounter, home::Home,
13+
time_management_tab::TimeManagementTab, Component,
1314
},
1415
config::Config,
1516
tui::{Event, Tui},
@@ -39,6 +40,7 @@ pub enum Mode {
3940
Home,
4041
Explorer,
4142
Filter,
43+
TimeTracking,
4244
}
4345

4446
impl App {
@@ -54,6 +56,7 @@ impl App {
5456
Box::<FpsCounter>::default(),
5557
Box::new(ExplorerTab::new()),
5658
Box::new(FilterTab::new()),
59+
Box::new(TimeManagementTab::new()),
5760
],
5861
should_quit: false,
5962
should_suspend: false,

src/components.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ pub mod explorer_tab;
1616
pub mod filter_tab;
1717
pub mod fps;
1818
pub mod home;
19+
pub mod time_management_tab;
1920

2021
/// `Component` is a trait that represents a visual and interactive element of the user interface.
2122
///

src/components/home.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ impl Home {
2323
if let Err(e) = tx.send(match self.selected_tab {
2424
SelectedTab::Explorer => Action::Focus(Mode::Explorer),
2525
SelectedTab::Filter => Action::Focus(Mode::Filter),
26+
SelectedTab::TimeManagement => Action::Focus(Mode::TimeTracking),
2627
}) {
2728
error!("Could not focus selected tab: {e}");
2829
}
@@ -104,6 +105,8 @@ enum SelectedTab {
104105
Explorer,
105106
#[strum(to_string = "Filter")]
106107
Filter,
108+
#[strum(to_string = "Time Management")]
109+
TimeManagement,
107110
}
108111

109112
impl SelectedTab {

src/components/time_management_tab.rs

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
use color_eyre::Result;
2+
use ratatui::prelude::*;
3+
use tokio::sync::mpsc::UnboundedSender;
4+
5+
use super::Component;
6+
7+
use crate::app::Mode;
8+
use crate::tui::Tui;
9+
use crate::widgets::help_menu::HelpMenu;
10+
use crate::{action::Action, config::Config};
11+
12+
#[derive(Default)]
13+
pub struct TimeManagementTab<'a> {
14+
command_tx: Option<UnboundedSender<Action>>,
15+
config: Config,
16+
is_focused: bool,
17+
/// Whether the help panel is open or not
18+
show_help: bool,
19+
help_menu_wigdet: HelpMenu<'a>,
20+
}
21+
impl<'a> TimeManagementTab<'a> {
22+
pub fn new() -> Self {
23+
Self::default()
24+
}
25+
}
26+
impl<'a> Component for TimeManagementTab<'a> {
27+
fn draw(&mut self, frame: &mut Frame, area: Rect) -> Result<()> {
28+
if !self.is_focused {
29+
return Ok(());
30+
}
31+
let _ = frame;
32+
let _ = area;
33+
Ok(())
34+
}
35+
36+
fn register_action_handler(&mut self, tx: UnboundedSender<Action>) -> Result<()> {
37+
let _ = tx; // to appease clippy
38+
Ok(())
39+
}
40+
41+
fn register_config_handler(&mut self, config: Config) -> Result<()> {
42+
self.config = config;
43+
Ok(())
44+
}
45+
46+
fn update(&mut self, tui: Option<&mut Tui>, action: Action) -> Result<Option<Action>> {
47+
if !self.is_focused {
48+
match action {
49+
Action::Focus(Mode::TimeTracking) => self.is_focused = true,
50+
Action::Focus(mode) if !(mode == Mode::TimeTracking) => self.is_focused = false,
51+
_ => (),
52+
}
53+
} else if self.show_help {
54+
match action {
55+
Action::ViewUp | Action::Up => self.help_menu_wigdet.scroll_up(),
56+
Action::ViewDown | Action::Down => self.help_menu_wigdet.scroll_down(),
57+
Action::Help | Action::Escape | Action::Enter => {
58+
self.show_help = !self.show_help;
59+
}
60+
_ => (),
61+
}
62+
} else {
63+
match action {
64+
Action::Focus(mode) if mode != Mode::TimeTracking => self.is_focused = false,
65+
Action::Focus(Mode::TimeTracking) => self.is_focused = true,
66+
67+
Action::Help => self.show_help = !self.show_help,
68+
_ => (),
69+
}
70+
}
71+
Ok(None)
72+
}
73+
74+
fn escape_blocking_mode(&self) -> Vec<Action> {
75+
std::vec![]
76+
}
77+
78+
fn blocking_mode(&self) -> bool {
79+
false
80+
}
81+
}

0 commit comments

Comments
 (0)