From 9a432be5ca372a908739c37f096f6696905d65ba Mon Sep 17 00:00:00 2001 From: Robin Jarry Date: Mon, 20 Feb 2023 22:39:42 +0100 Subject: wip Signed-off-by: Robin Jarry --- derive-macro/src/derives.rs | 10 +++-- derive-macro/src/dummies.rs | 14 +++++- derive-macro/src/lib.rs | 13 ++++-- src/config/templates.rs | 13 +++++- src/config/ui.rs | 102 ++++++++++++++++++++++++++++++++++++++++---- 5 files changed, 135 insertions(+), 17 deletions(-) diff --git a/derive-macro/src/derives.rs b/derive-macro/src/derives.rs index fdb83a0d..3db58586 100644 --- a/derive-macro/src/derives.rs +++ b/derive-macro/src/derives.rs @@ -9,7 +9,7 @@ use syn::{self, Data, DataStruct, DeriveInput, Field, Fields, Generics, Ident}; use crate::dummies; use crate::item::Item; -pub fn derive_ini(input: &DeriveInput) -> TokenStream { +pub fn derive_ini_parse(input: &DeriveInput) -> TokenStream { let ident = &input.ident; match input.data { @@ -17,7 +17,7 @@ pub fn derive_ini(input: &DeriveInput) -> TokenStream { fields: Fields::Named(ref fields), .. }) => { - dummies::ini(ident); + dummies::ini_parse(ident); let item = Item::from_args_struct(input); let fields = fields @@ -30,10 +30,14 @@ pub fn derive_ini(input: &DeriveInput) -> TokenStream { .collect::>(); gen_for_struct(&item, ident, &input.generics, &fields) } - _ => abort_call_site!("`#[derive(Ini)]` only supports non-tuple structs"), + _ => abort_call_site!("`#[derive(IniParse)]` only supports non-tuple structs"), } } +pub fn derive_ini_dump(input: &DeriveInput) -> TokenStream { + abort_call_site!("`#[derive(IniDump)]` is not implemented") +} + fn gen_for_struct( item: &Item, name: &Ident, diff --git a/derive-macro/src/dummies.rs b/derive-macro/src/dummies.rs index 3abd39a4..e61e2e8c 100644 --- a/derive-macro/src/dummies.rs +++ b/derive-macro/src/dummies.rs @@ -4,10 +4,20 @@ use proc_macro2::Ident; use proc_macro_error::append_dummy; use quote::quote; -pub fn ini(name: &Ident) { +pub fn ini_parse(name: &Ident) { append_dummy(quote! { impl #name { - pub fn parse<'a>(i: &'a ::ini::Ini) -> ::std::Result { + pub fn parse_ini<'a>(i: &'a ::ini::Ini) -> ::std::Result { + unimplemented!() + } + } + }); +} + +pub fn ini_dump(name: &Ident) { + append_dummy(quote! { + impl #name { + pub fn dump_ini<'b>(&self, to: &'b dyn ::std::io::Write) -> ::std::io::Result<()> { unimplemented!() } } diff --git a/derive-macro/src/lib.rs b/derive-macro/src/lib.rs index 513c2b20..8bd5931b 100644 --- a/derive-macro/src/lib.rs +++ b/derive-macro/src/lib.rs @@ -14,9 +14,16 @@ mod dummies; mod item; mod spanned; -#[proc_macro_derive(IniMap, attributes(key, default, parse_with))] +#[proc_macro_derive(IniParse, attributes(key, default, parse_with))] #[proc_macro_error] -pub fn ini(input: TokenStream) -> TokenStream { +pub fn ini_parse(input: TokenStream) -> TokenStream { let input: DeriveInput = parse_macro_input!(input); - derives::derive_ini(&input).into() + derives::derive_ini_parse(&input).into() +} + +#[proc_macro_derive(IniDump, attributes(key, default, parse_with))] +#[proc_macro_error] +pub fn ini_dump(input: TokenStream) -> TokenStream { + let input: DeriveInput = parse_macro_input!(input); + derives::derive_ini_dump(&input).into() } diff --git a/src/config/templates.rs b/src/config/templates.rs index 00e9cf59..e5299bd0 100644 --- a/src/config/templates.rs +++ b/src/config/templates.rs @@ -3,8 +3,19 @@ use std::fmt; -use gtmpl::Template; +use gtmpl::{Template, TemplateError}; pub fn debug_template(t: &Template, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { f.write_fmt(format_args!("Template({:?})", t.text)) } + +pub fn parse_ini( + ini: &ini::Properties, + key: &str, + default: &str, +) -> Result { + let text = ini.get_all(key).last().unwrap_or(default); + let mut t = Template::with_name(text); + t.parse(text)?; + Ok(t) +} diff --git a/src/config/ui.rs b/src/config/ui.rs index bab96f48..c7a39f42 100644 --- a/src/config/ui.rs +++ b/src/config/ui.rs @@ -3,13 +3,14 @@ use std::collections::HashMap; -use anyhow::{Error, Result}; +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)] @@ -91,19 +92,104 @@ pub struct UiConfig { contextual_cache: HashMap, } -#[derive(Debug)] -struct UiContext {} +#[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, -#[derive(Debug)] + // 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)] +#[derive(Debug, Clone)] struct UiContextKey {} impl UiConfig { pub fn parse(ini: &Ini) -> Result { - let ui = ini.section(Some("ui")).unwrap_or(&Properties::new()); - - Ok(Self::default()) + 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() + }) } } -- cgit v1.2.3-54-g00ecf