// SPDX-License-Identifier: MIT // Copyright (c) 2023 Robin Jarry use std::collections::HashMap; use anyhow::Result; use derivative::Derivative; use gtmpl::Template; use ini::{Ini, Properties}; use crate::config::columns::ColumnDef; use crate::config::style::StyleSet; use crate::config::templates; #[derive(Derivative, Default)] #[derivative(Debug)] pub struct UiConfig { // message list pub index_columns: Vec, pub column_separator: String, pub empty_message: String, pub threading_enabled: bool, pub force_client_threads: bool, pub client_threads_delay: time::Duration, pub sort: Vec, pub reverse_order: bool, pub reverse_thread_order: bool, pub sort_thread_siblings: bool, // dirlist #[derivative(Debug(format_with = "crate::config::templates::debug_template"))] pub dirlist_left: Template, #[derivative(Debug(format_with = "crate::config::templates::debug_template"))] pub dirlist_right: Template, pub sidebar_width: u8, pub empty_dirlist: String, pub dirlist_delay: time::Duration, pub dirlist_tree: bool, pub dirlist_collapse: u8, // time formats pub timestamp_format: String, pub this_day_time_format: String, pub this_week_time_format: String, pub this_year_time_format: String, pub msgview_timestamp_format: String, pub msgview_this_day_time_format: String, pub msgview_this_week_time_format: String, pub msgview_this_year_time_format: String, // icons pub icon_unencrypted: String, pub icon_encrypted: String, pub icon_signed: String, pub icon_signed_encrypted: String, pub icon_unknown: String, pub icon_invalid: String, pub icon_attachment: String, // style pub stylesets_dirs: Vec, pub styleset_name: String, style: StyleSet, // general appearance pub border_vertical: char, pub border_horizontal: char, pub spinner: String, pub spinner_delimiter: String, pub spinner_interval: time::Duration, pub pinned_tab_marker: String, // behaviour pub automark_read: bool, pub next_message_on_delete: bool, pub mouse_enabled: bool, pub fuzzy_complete: bool, pub new_message_bell: bool, pub completion_delay: time::Duration, pub completion_min_chars: u8, pub completion_popovers: bool, // tabs #[derivative(Debug(format_with = "crate::config::templates::debug_template"))] pub tab_title_account: Template, #[derivative(Debug(format_with = "crate::config::templates::debug_template"))] pub tab_title_composer: Template, // contextual contextual_sections: Vec, contextual_counts: HashMap, contextual_cache: HashMap, } #[derive(Debug, Clone)] struct UiContext { // message list pub index_columns: Vec, pub column_separator: String, pub empty_message: String, pub threading_enabled: bool, pub force_client_threads: bool, pub client_threads_delay: time::Duration, pub sort: Vec, pub reverse_order: bool, pub reverse_thread_order: bool, pub sort_thread_siblings: bool, // dirlist #[derivative(Debug(format_with = "crate::config::templates::debug_template"))] pub dirlist_left: Template, #[derivative(Debug(format_with = "crate::config::templates::debug_template"))] pub dirlist_right: Template, pub sidebar_width: u8, pub empty_dirlist: String, pub dirlist_delay: time::Duration, pub dirlist_tree: bool, pub dirlist_collapse: u8, // time formats pub timestamp_format: String, pub this_day_time_format: String, pub this_week_time_format: String, pub this_year_time_format: String, pub msgview_timestamp_format: String, pub msgview_this_day_time_format: String, pub msgview_this_week_time_format: String, pub msgview_this_year_time_format: String, // icons pub icon_unencrypted: String, pub icon_encrypted: String, pub icon_signed: String, pub icon_signed_encrypted: String, pub icon_unknown: String, pub icon_invalid: String, pub icon_attachment: String, // style pub stylesets_dirs: Vec, pub styleset_name: String, style: StyleSet, // general appearance pub border_vertical: char, pub border_horizontal: char, pub spinner: String, pub spinner_delimiter: String, pub spinner_interval: time::Duration, pub pinned_tab_marker: String, // behaviour pub automark_read: bool, pub next_message_on_delete: bool, pub mouse_enabled: bool, pub fuzzy_complete: bool, pub new_message_bell: bool, pub completion_delay: time::Duration, pub completion_min_chars: u8, pub completion_popovers: bool, // tabs #[derivative(Debug(format_with = "crate::config::templates::debug_template"))] pub tab_title_account: Template, #[derivative(Debug(format_with = "crate::config::templates::debug_template"))] pub tab_title_composer: Template, // contextual contextual_counts: HashMap, contextual_cache: HashMap, } #[derive(Debug, Clone)] enum UiContextType {} #[derive(Debug, Clone)] struct UiContextKey {} impl UiConfig { pub fn parse(ini: &Ini) -> Result { let empty = Properties::new(); let ui = ini.section(Some("ui")).unwrap_or(&empty); Ok(UiConfig { styleset_name: ui .get_all("styleset") .last() .unwrap_or("default") .to_string(), tab_title_account: templates::parse_ini(ui, "tab-title-account", "{{.Account}}")?, tab_title_composer: templates::parse_ini(ui, "tab-title-composer", "{{.Subject}}")?, ..Default::default() }) } }