aboutsummaryrefslogtreecommitdiff
path: root/src/config/ui.rs
blob: c7a39f4260a1301fc9c1a082a7ec93b8308afcd1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
// 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<ColumnDef>,
    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<String>,
    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<String>,
    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<UiContext>,
    contextual_counts: HashMap<UiContextType, usize>,
    contextual_cache: HashMap<UiContextKey, UiConfig>,
}

#[derive(Debug, Clone)]
struct UiContext {
    // message list
    pub index_columns: Vec<ColumnDef>,
    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<String>,
    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<String>,
    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<UiContextType, usize>,
    contextual_cache: HashMap<UiContextKey, UiConfig>,
}

#[derive(Debug, Clone)]
enum UiContextType {}

#[derive(Debug, Clone)]
struct UiContextKey {}

impl UiConfig {
    pub fn parse(ini: &Ini) -> Result<Self> {
        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()
        })
    }
}