This commit is contained in:
Dheepak Krishnamurthy 2023-09-25 05:41:42 -04:00
parent 0c9b3b03dc
commit 9b7b83607a
3 changed files with 12 additions and 5 deletions

View file

@ -2,7 +2,7 @@
"keybindings": { "keybindings": {
// KeyBindings for TaskReport // KeyBindings for TaskReport
"TaskReport": { "TaskReport": {
"<q>": "Quit", // Quit the application "<q><q>": "Quit", // Quit the application
"<Ctrl-d>": "Quit", // Another way to quit "<Ctrl-d>": "Quit", // Another way to quit
"<Ctrl-c>": "Quit", // Yet another way to quit "<Ctrl-c>": "Quit", // Yet another way to quit
"<Ctrl-z>": "Suspend" // Suspend the application "<Ctrl-z>": "Suspend" // Suspend the application

View file

@ -1,4 +1,5 @@
use color_eyre::eyre::Result; use color_eyre::eyre::Result;
use crossterm::event::KeyEvent;
use serde_derive::{Deserialize, Serialize}; use serde_derive::{Deserialize, Serialize};
use tokio::sync::mpsc; use tokio::sync::mpsc;
@ -26,6 +27,7 @@ pub struct App {
pub should_quit: bool, pub should_quit: bool,
pub should_suspend: bool, pub should_suspend: bool,
pub mode: Mode, pub mode: Mode,
pub last_tick_key_events: Vec<KeyEvent>,
} }
impl App { impl App {
@ -41,6 +43,7 @@ impl App {
should_suspend: false, should_suspend: false,
config, config,
mode, mode,
last_tick_key_events: Vec::new(),
}) })
} }
@ -72,8 +75,9 @@ impl App {
tui::Event::Render => command_tx.send(Command::Render)?, tui::Event::Render => command_tx.send(Command::Render)?,
tui::Event::Resize(x, y) => command_tx.send(Command::Resize(x, y))?, tui::Event::Resize(x, y) => command_tx.send(Command::Resize(x, y))?,
tui::Event::Key(key) => { tui::Event::Key(key) => {
let command = if let Some(keymap) = self.config.keybindings.get(&self.mode) { self.last_tick_key_events.push(key);
if let Some(command) = keymap.get(&vec![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())?; command_tx.send(command.clone())?;
}; };
}; };
@ -92,6 +96,9 @@ impl App {
log::debug!("{command:?}"); log::debug!("{command:?}");
} }
match command { match command {
Command::Tick => {
self.last_tick_key_events.drain(..);
},
Command::Quit => self.should_quit = true, Command::Quit => self.should_quit = true,
Command::Suspend => self.should_suspend = true, Command::Suspend => self.should_suspend = true,
Command::Resume => self.should_suspend = false, Command::Resume => self.should_suspend = false,

View file

@ -25,10 +25,10 @@ pub struct Cli {
)] )]
pub taskrc: Option<PathBuf>, 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, 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, pub frame_rate: f64,
#[arg(short, long, value_name = "STRING", help = "Sets default report")] #[arg(short, long, value_name = "STRING", help = "Sets default report")]