Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
kdheepak committed Sep 25, 2023
1 parent 0c9b3b0 commit 9b7b836
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .config/config.json5
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"keybindings": {
// KeyBindings for TaskReport
"TaskReport": {
"<q>": "Quit", // Quit the application
"<q><q>": "Quit", // Quit the application
"<Ctrl-d>": "Quit", // Another way to quit
"<Ctrl-c>": "Quit", // Yet another way to quit
"<Ctrl-z>": "Suspend" // Suspend the application
Expand Down
11 changes: 9 additions & 2 deletions src/app.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use color_eyre::eyre::Result;
use crossterm::event::KeyEvent;
use serde_derive::{Deserialize, Serialize};
use tokio::sync::mpsc;

Expand Down Expand Up @@ -26,6 +27,7 @@ pub struct App {
pub should_quit: bool,
pub should_suspend: bool,
pub mode: Mode,
pub last_tick_key_events: Vec<KeyEvent>,
}

impl App {
Expand All @@ -41,6 +43,7 @@ impl App {
should_suspend: false,
config,
mode,
last_tick_key_events: Vec::new(),
})
}

Expand Down Expand Up @@ -72,8 +75,9 @@ impl App {
tui::Event::Render => command_tx.send(Command::Render)?,
tui::Event::Resize(x, y) => command_tx.send(Command::Resize(x, y))?,
tui::Event::Key(key) => {
let command = if let Some(keymap) = self.config.keybindings.get(&self.mode) {
if let Some(command) = keymap.get(&vec![key]) {
self.last_tick_key_events.push(key);
if let Some(keymap) = self.config.keybindings.get(&self.mode) {
if let Some(command) = keymap.get(&self.last_tick_key_events) {
command_tx.send(command.clone())?;
};
};
Expand All @@ -92,6 +96,9 @@ impl App {
log::debug!("{command:?}");
}
match command {
Command::Tick => {
self.last_tick_key_events.drain(..);
},
Command::Quit => self.should_quit = true,
Command::Suspend => self.should_suspend = true,
Command::Resume => self.should_suspend = false,
Expand Down
4 changes: 2 additions & 2 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ pub struct Cli {
)]
pub taskrc: Option<PathBuf>,

#[arg(value_name = "FLOAT", help = "Tick rate", default_value_t = 4.0)]
#[arg(value_name = "FLOAT", help = "Tick rate, i.e. number of ticks per second", default_value_t = 1.0)]
pub tick_rate: f64,

#[arg(value_name = "FLOAT", help = "Frame rate", default_value_t = 60.0)]
#[arg(value_name = "FLOAT", help = "Frame rate, i.e. number of frames per second", default_value_t = 60.0)]
pub frame_rate: f64,

#[arg(short, long, value_name = "STRING", help = "Sets default report")]
Expand Down

0 comments on commit 9b7b836

Please sign in to comment.