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 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

View file

@ -1,4 +1,5 @@
use color_eyre::eyre::Result;
use crossterm::event::KeyEvent;
use serde_derive::{Deserialize, Serialize};
use tokio::sync::mpsc;
@ -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 {
@ -41,6 +43,7 @@ impl App {
should_suspend: false,
config,
mode,
last_tick_key_events: Vec::new(),
})
}
@ -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())?;
};
};
@ -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,

View file

@ -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")]