mirror of
https://github.com/kdheepak/taskwarrior-tui.git
synced 2025-08-27 06:37:19 +02:00
Make tick rate configurable
This commit is contained in:
parent
de0d732c34
commit
5f15e5efd0
3 changed files with 56 additions and 44 deletions
|
@ -45,6 +45,7 @@ pub struct Config {
|
||||||
pub print_empty_columns: bool,
|
pub print_empty_columns: bool,
|
||||||
pub due: usize,
|
pub due: usize,
|
||||||
pub rule_precedence_color: Vec<String>,
|
pub rule_precedence_color: Vec<String>,
|
||||||
|
pub uda_tick_rate: u64,
|
||||||
pub uda_task_detail_prefetch: usize,
|
pub uda_task_detail_prefetch: usize,
|
||||||
pub uda_task_report_show_info: bool,
|
pub uda_task_report_show_info: bool,
|
||||||
pub uda_task_report_looping: bool,
|
pub uda_task_report_looping: bool,
|
||||||
|
@ -74,6 +75,7 @@ impl Config {
|
||||||
let data_location = Self::get_data_location();
|
let data_location = Self::get_data_location();
|
||||||
let due = Self::get_due();
|
let due = Self::get_due();
|
||||||
let rule_precedence_color = Self::get_rule_precedence_color();
|
let rule_precedence_color = Self::get_rule_precedence_color();
|
||||||
|
let uda_tick_rate = Self::get_uda_tick_rate();
|
||||||
let uda_task_detail_prefetch = Self::get_uda_task_detail_prefetch();
|
let uda_task_detail_prefetch = Self::get_uda_task_detail_prefetch();
|
||||||
let uda_task_report_show_info = Self::get_uda_task_report_show_info();
|
let uda_task_report_show_info = Self::get_uda_task_report_show_info();
|
||||||
let uda_task_report_looping = Self::get_uda_task_report_looping();
|
let uda_task_report_looping = Self::get_uda_task_report_looping();
|
||||||
|
@ -95,6 +97,7 @@ impl Config {
|
||||||
data_location,
|
data_location,
|
||||||
due,
|
due,
|
||||||
rule_precedence_color,
|
rule_precedence_color,
|
||||||
|
uda_tick_rate,
|
||||||
uda_task_detail_prefetch,
|
uda_task_detail_prefetch,
|
||||||
uda_task_report_show_info,
|
uda_task_report_show_info,
|
||||||
uda_task_report_looping,
|
uda_task_report_looping,
|
||||||
|
@ -116,6 +119,7 @@ impl Config {
|
||||||
data_location,
|
data_location,
|
||||||
due,
|
due,
|
||||||
rule_precedence_color,
|
rule_precedence_color,
|
||||||
|
uda_tick_rate,
|
||||||
uda_task_detail_prefetch,
|
uda_task_detail_prefetch,
|
||||||
uda_task_report_show_info,
|
uda_task_report_show_info,
|
||||||
uda_task_report_looping,
|
uda_task_report_looping,
|
||||||
|
@ -146,6 +150,7 @@ impl Config {
|
||||||
print_empty_columns,
|
print_empty_columns,
|
||||||
due,
|
due,
|
||||||
rule_precedence_color,
|
rule_precedence_color,
|
||||||
|
uda_tick_rate,
|
||||||
uda_task_detail_prefetch,
|
uda_task_detail_prefetch,
|
||||||
uda_task_report_show_info,
|
uda_task_report_show_info,
|
||||||
uda_task_report_looping,
|
uda_task_report_looping,
|
||||||
|
@ -423,6 +428,14 @@ impl Config {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn get_uda_tick_rate() -> u64 {
|
||||||
|
Self::get_config("uda.taskwarrior-tui.tick-rate")
|
||||||
|
.await
|
||||||
|
.unwrap_or_default()
|
||||||
|
.parse::<u64>()
|
||||||
|
.unwrap_or(250)
|
||||||
|
}
|
||||||
|
|
||||||
async fn get_uda_task_detail_prefetch() -> usize {
|
async fn get_uda_task_detail_prefetch() -> usize {
|
||||||
Self::get_config("uda.taskwarrior-tui.task-report.task-detail-prefetch")
|
Self::get_config("uda.taskwarrior-tui.task-report.task-detail-prefetch")
|
||||||
.await
|
.await
|
||||||
|
|
35
src/main.rs
35
src/main.rs
|
@ -53,31 +53,37 @@ fn main() -> Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn tui_main(_config: &str) -> Result<()> {
|
async fn tui_main(_config: &str) -> Result<()> {
|
||||||
// Terminal initialization
|
|
||||||
let terminal = setup_terminal();
|
|
||||||
|
|
||||||
panic::set_hook(Box::new(|panic_info| {
|
panic::set_hook(Box::new(|panic_info| {
|
||||||
destruct_terminal();
|
destruct_terminal();
|
||||||
better_panic::Settings::auto().create_panic_handler()(panic_info);
|
better_panic::Settings::auto().create_panic_handler()(panic_info);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
let maybeapp = TaskwarriorTuiApp::new();
|
||||||
|
if maybeapp.is_err() {
|
||||||
|
destruct_terminal();
|
||||||
|
return Err(maybeapp.err().unwrap());
|
||||||
|
}
|
||||||
|
|
||||||
|
let app = Arc::new(Mutex::new(maybeapp.unwrap()));
|
||||||
|
let terminal = Arc::new(Mutex::new(setup_terminal()));
|
||||||
|
|
||||||
|
{
|
||||||
|
let mut terminal = terminal.lock().await;
|
||||||
|
app.lock().await.render(&mut terminal).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
// Setup event handlers
|
// Setup event handlers
|
||||||
let events = Events::with_config(EventConfig {
|
let events = Events::with_config(EventConfig {
|
||||||
tick_rate: Duration::from_millis(250),
|
tick_rate: Duration::from_millis(app.lock().await.config.uda_tick_rate),
|
||||||
});
|
});
|
||||||
|
|
||||||
let maybeapp = TaskwarriorTuiApp::new();
|
|
||||||
match maybeapp {
|
|
||||||
Ok(app) => {
|
|
||||||
let app = Arc::new(Mutex::new(app));
|
|
||||||
let terminal = Arc::new(Mutex::new(terminal));
|
|
||||||
loop {
|
loop {
|
||||||
let handle = {
|
let handle = {
|
||||||
let app = app.clone();
|
let app = app.clone();
|
||||||
let terminal = terminal.clone();
|
let terminal = terminal.clone();
|
||||||
task::spawn_local(async move {
|
task::spawn_local(async move {
|
||||||
let mut t = terminal.lock().await;
|
let mut terminal = terminal.lock().await;
|
||||||
app.lock().await.render(&mut t).unwrap();
|
app.lock().await.render(&mut terminal).unwrap();
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
// Handle input
|
// Handle input
|
||||||
|
@ -104,12 +110,5 @@ async fn tui_main(_config: &str) -> Result<()> {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
destruct_terminal();
|
|
||||||
Err(e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,7 +88,7 @@ impl Events {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut delay = Delay::new(Duration::from_millis(250)).fuse();
|
let mut delay = Delay::new(tick_rate).fuse();
|
||||||
let mut event = reader.next().fuse();
|
let mut event = reader.next().fuse();
|
||||||
|
|
||||||
select! {
|
select! {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue