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,7 +115,8 @@ 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 {
join!(
color, color,
filter, filter,
data_location, data_location,
@ -137,7 +138,8 @@ impl Config {
uda_style_calendar_title, uda_style_calendar_title,
uda_style_context_active, uda_style_context_active,
uda_shortcuts, 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,7 +151,8 @@ impl KeyConfig {
context_menu, context_menu,
next_tab, next_tab,
previous_tab, previous_tab,
) = join!( ) = task::block_on(async {
join!(
quit, quit,
refresh, refresh,
go_to_bottom, go_to_bottom,
@ -177,7 +178,8 @@ impl KeyConfig {
context_menu, context_menu,
next_tab, next_tab,
previous_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);