aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/pomo/mod.rs19
-rw-r--r--src/pomo/state.rs17
-rw-r--r--src/pomo/ui.rs27
3 files changed, 58 insertions, 5 deletions
diff --git a/src/pomo/mod.rs b/src/pomo/mod.rs
index a47d138..9c02653 100644
--- a/src/pomo/mod.rs
+++ b/src/pomo/mod.rs
@@ -9,7 +9,8 @@ use crossterm::{
};
use ratatui::prelude::*;
use std::io;
-use std::time::{Duration, Instant}; // Fixed: Added Instant here
+use std::time::{Duration, Instant};
+use crossterm::event::KeyModifiers;
impl Pomo {
pub fn run(&mut self) -> io::Result<()> {
@@ -33,10 +34,18 @@ impl Pomo {
if let Event::Key(key) = event::read()? {
match key.code {
KeyCode::Char('q') => self.should_quit = true,
- KeyCode::Char(' ') => self.toggle_timer(),
- KeyCode::Char('j') | KeyCode::Down => self.next_task(),
- KeyCode::Char('k') | KeyCode::Up => self.previous_task(),
- KeyCode::Enter => self.toggle_task(),
+ KeyCode::Char('?') => self.show_help = !self.show_help,
+ KeyCode::Char('h') if key.modifiers.contains(KeyModifiers::CONTROL) => {
+ self.show_help = !self.show_help
+ },
+ // Only allow other inputs if help isn't showing (to keep it clean)
+ _ if !self.show_help => match key.code {
+ KeyCode::Char(' ') => self.toggle_timer(),
+ KeyCode::Char('j') | KeyCode::Down => self.next_task(),
+ KeyCode::Char('k') | KeyCode::Up => self.previous_task(),
+ KeyCode::Enter => self.toggle_task(),
+ _ => {}
+ },
_ => {}
}
}
diff --git a/src/pomo/state.rs b/src/pomo/state.rs
index 3076174..f4a7a5e 100644
--- a/src/pomo/state.rs
+++ b/src/pomo/state.rs
@@ -31,6 +31,12 @@ pub struct Pomo {
pub tasks: Vec<Task>,
pub task_state: ListState,
pub should_quit: bool,
+ pub show_help: bool
+}
+
+pub struct Command {
+ pub key: &'static str,
+ pub desc: &'static str,
}
impl Pomo {
@@ -47,6 +53,7 @@ impl Pomo {
tasks: dummy_tasks,
task_state: ListState::default(),
should_quit: false,
+ show_help: false
}
}
@@ -106,4 +113,14 @@ impl Pomo {
self.tasks[i].is_done = !self.tasks[i].is_done;
}
}
+
+ pub fn get_commands(&self) -> Vec<Command> {
+ vec![
+ Command { key: "Space", desc: "Toggle Timer" },
+ Command { key: "j/k", desc: "Navigate Tasks" },
+ Command { key: "Enter", desc: "Toggle Done" },
+ Command { key: "?", desc: "Toggle Help" },
+ Command { key: "q", desc: "Quit" },
+ ]
+ }
}
diff --git a/src/pomo/ui.rs b/src/pomo/ui.rs
index e1f1f5d..1a7fb49 100644
--- a/src/pomo/ui.rs
+++ b/src/pomo/ui.rs
@@ -51,6 +51,33 @@ pub fn render(f: &mut Frame, app: &mut Pomo) {
.highlight_symbol(" ");
f.render_stateful_widget(list, chunks[1], &mut app.task_state);
+
+ if app.show_help {
+ let help_area = centered_rect(30, 30, f.area()); // Smaller popup
+
+ // Clear the area underneath so the main UI doesn't interfere
+ f.render_widget(Clear, help_area);
+
+ let help_block = Block::default()
+ .title(" Help / Controls ")
+ .borders(Borders::ALL)
+ .border_type(BorderType::Rounded)
+ .border_style(Style::default().fg(accent_color));
+
+ let commands = app.get_commands();
+ let help_text: Vec<ListItem> = commands
+ .iter()
+ .map(|c| {
+ ListItem::new(Line::from(vec![
+ Span::styled(format!("{:<7}", c.key), Style::default().fg(accent_color).add_modifier(Modifier::BOLD)),
+ Span::raw(c.desc),
+ ]))
+ })
+ .collect();
+
+ let help_list = List::new(help_text).block(help_block);
+ f.render_widget(help_list, help_area);
+ }
}
fn centered_rect(percent_x: u16, percent_y: u16, r: Rect) -> Rect {