use anyhow::{Context, Result}; use std::collections::HashMap; use std::error::Error; use std::process::Command; use std::str; use tui::style::{Color, Modifier, Style}; trait TaskWarriorBool { fn get_bool(&self) -> Option; } impl TaskWarriorBool for String { fn get_bool(&self) -> Option { if self == "true" || self == "1" || self == "y" || self == "yes" || self == "on" { Some(true) } else if self == "false" || self == "0" || self == "n" || self == "no" || self == "off" { Some(false) } else { None } } } impl TaskWarriorBool for str { fn get_bool(&self) -> Option { if self == "true" || self == "1" || self == "y" || self == "yes" || self == "on" { Some(true) } else if self == "false" || self == "0" || self == "n" || self == "no" || self == "off" { Some(false) } else { None } } } #[derive(Debug)] pub struct Config { pub enabled: bool, pub color: HashMap, pub filter: String, pub data_location: String, pub obfuscate: bool, pub print_empty_columns: bool, pub due: usize, pub rule_precedence_color: Vec, pub uda_task_report_show_info: bool, pub uda_task_report_looping: bool, pub uda_selection_indicator: String, pub uda_mark_indicator: String, pub uda_unmark_indicator: String, pub uda_selection_bold: bool, pub uda_selection_italic: bool, pub uda_selection_dim: bool, pub uda_selection_blink: bool, pub uda_calendar_months_per_row: usize, pub uda_style_context_active: Style, pub uda_style_calendar_title: Style, pub uda_shortcuts: Vec, } impl Config { pub fn default() -> Result { let bool_collection = Self::get_bool_collection(); Ok(Self { enabled: true, obfuscate: bool_collection.get("obfuscate").cloned().unwrap_or(false), print_empty_columns: bool_collection.get("print_empty_columns").cloned().unwrap_or(false), color: Self::get_color_collection()?, filter: Self::get_filter(), data_location: Self::get_data_location(), due: Self::get_due(), rule_precedence_color: Self::get_rule_precedence_color(), uda_task_report_show_info: Self::get_uda_task_report_show_info(), uda_task_report_looping: Self::get_uda_task_report_looping(), uda_selection_indicator: Self::get_uda_selection_indicator(), uda_mark_indicator: Self::get_uda_mark_indicator(), uda_unmark_indicator: Self::get_uda_unmark_indicator(), uda_selection_bold: Self::get_uda_selection_bold(), uda_selection_italic: Self::get_uda_selection_italic(), uda_selection_dim: Self::get_uda_selection_dim(), uda_selection_blink: Self::get_uda_selection_blink(), uda_calendar_months_per_row: Self::get_uda_months_per_row(), uda_style_calendar_title: Self::get_uda_style("calendar.title").unwrap_or_default(), uda_style_context_active: Self::get_uda_style("context.active").unwrap_or_default(), uda_shortcuts: Self::get_uda_shortcuts(), }) } fn get_bool_collection() -> HashMap { HashMap::new() } fn get_uda_shortcuts() -> Vec { let mut v = vec![]; for s in 0..=9 { let c = format!("uda.taskwarrior-tui.shortcuts.{}", s); let s = Self::get_config(&c).unwrap_or_default(); v.push(s); } v } fn get_uda_style(config: &str) -> Option