Make fewer system calls

This commit is contained in:
Dheepak Krishnamurthy 2021-04-03 23:01:00 -06:00
parent 77fe218456
commit e405ebe810
3 changed files with 60 additions and 55 deletions

View file

@ -219,7 +219,8 @@ impl TaskwarriorTuiApp {
} }
let data = String::from_utf8_lossy(&output.stdout); let data = String::from_utf8_lossy(&output.stdout);
let (c, kc) = task::block_on(async { try_join!(Config::new(&data), KeyConfig::new(&data)) })?; let c = Config::new(&data)?;
let kc = KeyConfig::new(&data)?;
let (w, h) = crossterm::terminal::size()?; let (w, h) = crossterm::terminal::size()?;

View file

@ -64,7 +64,7 @@ pub struct Config {
} }
impl Config { impl Config {
pub async fn new(data: &str) -> Result<Self> { pub fn new(data: &str) -> Result<Self> {
let bool_collection = Self::get_bool_collection(); let bool_collection = Self::get_bool_collection();
let enabled = true; let enabled = true;
@ -115,29 +115,31 @@ impl Config {
uda_style_calendar_title, uda_style_calendar_title,
uda_style_context_active, uda_style_context_active,
uda_shortcuts, uda_shortcuts,
) = join!( ) = task::block_on(async {
color, join!(
filter, color,
data_location, filter,
due, data_location,
rule_precedence_color, due,
uda_tick_rate, rule_precedence_color,
uda_prefill_task_metadata, uda_tick_rate,
uda_task_detail_prefetch, uda_prefill_task_metadata,
uda_task_report_show_info, uda_task_detail_prefetch,
uda_task_report_looping, uda_task_report_show_info,
uda_selection_indicator, uda_task_report_looping,
uda_mark_indicator, uda_selection_indicator,
uda_unmark_indicator, uda_mark_indicator,
uda_selection_bold, uda_unmark_indicator,
uda_selection_italic, uda_selection_bold,
uda_selection_dim, uda_selection_italic,
uda_selection_blink, uda_selection_dim,
uda_calendar_months_per_row, uda_selection_blink,
uda_style_calendar_title, uda_calendar_months_per_row,
uda_style_context_active, uda_style_calendar_title,
uda_shortcuts, uda_style_context_active,
); uda_shortcuts,
)
});
let color = color?; let color = color?;
let uda_style_calendar_title = uda_style_calendar_title.unwrap_or_default(); let uda_style_calendar_title = uda_style_calendar_title.unwrap_or_default();

View file

@ -92,13 +92,13 @@ impl Default for KeyConfig {
} }
impl KeyConfig { impl KeyConfig {
pub async fn new(data: &str) -> Result<Self> { pub fn new(data: &str) -> Result<Self> {
let mut kc = Self::default(); let mut kc = Self::default();
kc.update(data).await?; kc.update(data)?;
Ok(kc) Ok(kc)
} }
pub async fn update(&mut self, data: &str) -> Result<()> { pub fn update(&mut self, data: &str) -> Result<()> {
let quit = self.get_config("uda.taskwarrior-tui.keyconfig.quit", data); let quit = self.get_config("uda.taskwarrior-tui.keyconfig.quit", data);
let refresh = self.get_config("uda.taskwarrior-tui.keyconfig.refresh", data); let refresh = self.get_config("uda.taskwarrior-tui.keyconfig.refresh", data);
let go_to_bottom = self.get_config("uda.taskwarrior-tui.keyconfig.go-to-bottom", data); let go_to_bottom = self.get_config("uda.taskwarrior-tui.keyconfig.go-to-bottom", data);
@ -151,33 +151,35 @@ impl KeyConfig {
context_menu, context_menu,
next_tab, next_tab,
previous_tab, previous_tab,
) = join!( ) = task::block_on(async {
quit, join!(
refresh, quit,
go_to_bottom, refresh,
go_to_top, go_to_bottom,
down, go_to_top,
up, down,
page_down, up,
page_up, page_down,
delete, page_up,
done, delete,
start_stop, done,
select, start_stop,
select_all, select,
undo, select_all,
edit, undo,
modify, edit,
shell, modify,
log, shell,
add, log,
annotate, add,
filter, annotate,
zoom, filter,
context_menu, zoom,
next_tab, context_menu,
previous_tab, next_tab,
); previous_tab,
)
});
self.quit = quit.unwrap_or(self.quit); self.quit = quit.unwrap_or(self.quit);
self.refresh = refresh.unwrap_or(self.refresh); self.refresh = refresh.unwrap_or(self.refresh);