dotstate 0.3.4

A modern, secure, and user-friendly dotfile manager built with Rust
Documentation
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
//! Icon provider system for the application.
//!
//! Supports multiple icon sets: `NerdFonts`, Unicode emojis, and ASCII fallback.
//! Auto-detects terminal capabilities and allows user override via environment variable.

use std::env;

/// Available icon sets
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum IconSet {
    /// `NerdFonts` icons (requires NerdFont-patched font)
    NerdFonts,
    /// Unicode icons (works in most modern terminals)
    Unicode,
    /// Emoji icons (works in most modern terminals)
    Emoji,
    /// ASCII-only fallback (maximum compatibility)
    Ascii,
}

impl IconSet {
    /// Detect the best icon set for the current terminal
    #[must_use]
    pub fn detect() -> Self {
        // Check for explicit user override
        if let Ok(icons) = env::var("DOTSTATE_ICONS") {
            return match icons.to_lowercase().as_str() {
                "nerd" | "nerdfont" | "nerdfonts" => IconSet::NerdFonts,
                "unicode" => IconSet::Unicode,
                "emoji" => IconSet::Emoji,
                "ascii" | "plain" => IconSet::Ascii,
                _ => IconSet::Unicode, // Default fallback
            };
        }

        // Try to detect based on terminal type
        if Self::likely_supports_nerd_fonts() {
            IconSet::NerdFonts
        } else {
            IconSet::Unicode // Safe default
        }
    }

    /// Heuristic to detect if terminal likely supports `NerdFonts`
    fn likely_supports_nerd_fonts() -> bool {
        // Check TERM_PROGRAM for known terminals with good font support
        if let Ok(term_program) = env::var("TERM_PROGRAM") {
            matches!(
                term_program.as_str(),
                "iTerm.app" | "WezTerm" | "Alacritty" | "kitty" | "Ghostty" | "Hyper" | "Tabby"
            )
        } else {
            false
        }
    }

    /// Get the name of this icon set
    #[must_use]
    pub fn name(&self) -> &'static str {
        match self {
            IconSet::NerdFonts => "NerdFonts",
            IconSet::Unicode => "Unicode",
            IconSet::Emoji => "Emoji",
            IconSet::Ascii => "ASCII",
        }
    }
}

/// Icon provider that returns appropriate icons based on the selected icon set
pub struct Icons {
    icon_set: IconSet,
}

impl Icons {
    /// Create a new icon provider with auto-detection
    #[must_use]
    pub fn new() -> Self {
        Self {
            icon_set: IconSet::detect(),
        }
    }

    /// Create an icon provider with a specific icon set
    #[must_use]
    pub fn with_icon_set(icon_set: IconSet) -> Self {
        Self { icon_set }
    }

    /// Create an icon provider from config
    /// Priority: `DOTSTATE_ICONS` env var > config value > auto-detect
    #[must_use]
    pub fn from_config(config: &crate::config::Config) -> Self {
        // Environment variable takes precedence
        if env::var("DOTSTATE_ICONS").is_ok() {
            return Self::new(); // Will use env var via detect()
        }

        // Use config value
        Self::with_icon_set(config.get_icon_set())
    }

    /// Get the current icon set
    #[must_use]
    pub fn icon_set(&self) -> IconSet {
        self.icon_set
    }

    #[must_use]
    pub fn folder(&self) -> &'static str {
        match self.icon_set {
            IconSet::NerdFonts => "\u{ea83}", //
            IconSet::Unicode => "",
            IconSet::Emoji => "📁",
            IconSet::Ascii => "[DIR]",
        }
    }

    #[must_use]
    pub fn file(&self) -> &'static str {
        match self.icon_set {
            IconSet::NerdFonts => "\u{f15b}", //
            IconSet::Unicode => "",
            IconSet::Emoji => "📄",
            IconSet::Ascii => "[FILE]",
        }
    }

    #[must_use]
    pub fn sync(&self) -> &'static str {
        match self.icon_set {
            IconSet::NerdFonts => "\u{f14ce}", //
            IconSet::Unicode => "",
            IconSet::Emoji => "🔄",
            IconSet::Ascii => "[SYNC]",
        }
    }

    #[must_use]
    pub fn loading(&self) -> &'static str {
        match self.icon_set {
            IconSet::NerdFonts => "\u{f021}", //
            IconSet::Unicode => "",
            IconSet::Emoji => "",
            IconSet::Ascii => "[LD]",
        }
    }

    #[must_use]
    pub fn profile(&self) -> &'static str {
        match self.icon_set {
            IconSet::NerdFonts => "\u{f007}", //
            IconSet::Unicode => "",
            IconSet::Emoji => "👤",
            IconSet::Ascii => "[USR]",
        }
    }

    #[must_use]
    pub fn package(&self) -> &'static str {
        match self.icon_set {
            IconSet::NerdFonts => "\u{eb29}", //
            IconSet::Unicode => "",
            IconSet::Emoji => "📦",
            IconSet::Ascii => "[PKG]",
        }
    }

    #[must_use]
    pub fn git(&self) -> &'static str {
        match self.icon_set {
            IconSet::NerdFonts => "\u{f1d2}", //
            IconSet::Unicode => "",
            IconSet::Emoji => "🔧",
            IconSet::Ascii => "[GIT]",
        }
    }

    #[must_use]
    pub fn update(&self) -> &'static str {
        match self.icon_set {
            IconSet::NerdFonts => "\u{f06b0}", //
            IconSet::Unicode => "",
            IconSet::Emoji => "🎉",
            IconSet::Ascii => "[UPD]",
        }
    }

    #[must_use]
    pub fn menu(&self) -> &'static str {
        match self.icon_set {
            IconSet::NerdFonts => "\u{f0c9}", //
            IconSet::Unicode => "",
            IconSet::Emoji => "📋",
            IconSet::Ascii => "[MENU]",
        }
    }

    // === Status Icons ===

    #[must_use]
    pub fn success(&self) -> &'static str {
        match self.icon_set {
            IconSet::NerdFonts => "\u{f00c}", //
            IconSet::Unicode => "",
            IconSet::Emoji => "",
            IconSet::Ascii => "[OK]",
        }
    }

    #[must_use]
    pub fn warning(&self) -> &'static str {
        match self.icon_set {
            IconSet::NerdFonts => "\u{f071}", //
            IconSet::Unicode => "",
            IconSet::Emoji => "⚠️",
            IconSet::Ascii => "[!]",
        }
    }

    #[must_use]
    pub fn error(&self) -> &'static str {
        match self.icon_set {
            IconSet::NerdFonts => "\u{ebfb}", //
            IconSet::Unicode => "",
            IconSet::Emoji => "",
            IconSet::Ascii => "[X]",
        }
    }

    #[must_use]
    pub fn info(&self) -> &'static str {
        match self.icon_set {
            IconSet::NerdFonts => "\u{f05a}", //
            IconSet::Unicode => "",
            IconSet::Emoji => "ℹ️",
            IconSet::Ascii => "[i]",
        }
    }

    #[must_use]
    pub fn lightbulb(&self) -> &'static str {
        match self.icon_set {
            IconSet::NerdFonts => "\u{f0eb}", //
            IconSet::Unicode => "",
            IconSet::Emoji => "💡",
            IconSet::Ascii => "[IDEA]",
        }
    }
    #[must_use]
    pub fn active_profile(&self) -> &'static str {
        match self.icon_set {
            IconSet::NerdFonts => "\u{f005}", // Star or something distinct
            IconSet::Unicode => "",
            IconSet::Emoji => "",
            IconSet::Ascii => "[*]",
        }
    }

    #[must_use]
    pub fn inactive_profile(&self) -> &'static str {
        match self.icon_set {
            IconSet::NerdFonts => "\u{f111}", // Circle
            IconSet::Unicode => "",
            IconSet::Emoji => "",
            IconSet::Ascii => "[ ]",
        }
    }

    #[must_use]
    pub fn check(&self) -> &'static str {
        match self.icon_set {
            IconSet::NerdFonts => "\u{f42e}",
            IconSet::Unicode => "",
            IconSet::Emoji => "",
            IconSet::Ascii => "[x]",
        }
    }

    #[must_use]
    pub fn uncheck(&self) -> &'static str {
        match self.icon_set {
            IconSet::NerdFonts => " ",
            IconSet::Unicode => " ",
            IconSet::Emoji => " ",
            IconSet::Ascii => "[ ]",
        }
    }

    #[must_use]
    pub fn create(&self) -> &'static str {
        match self.icon_set {
            IconSet::NerdFonts => "\u{f067}", // Plus
            IconSet::Unicode => "+",
            IconSet::Emoji => "🆕",
            IconSet::Ascii => "[+]",
        }
    }

    #[must_use]
    pub fn github(&self) -> &'static str {
        match self.icon_set {
            IconSet::NerdFonts => "\u{f09b}", // GitHub logo
            IconSet::Unicode => "",
            IconSet::Emoji => "🔧", // Fallback to wrench for unicode as it's setup-related
            IconSet::Ascii => "[GH]",
        }
    }

    #[must_use]
    pub fn wrench(&self) -> &'static str {
        match self.icon_set {
            IconSet::NerdFonts => "\u{f0ad}", // Wrench
            IconSet::Unicode => "",
            IconSet::Emoji => "🔧",
            IconSet::Ascii => "[TOOL]",
        }
    }

    #[must_use]
    pub fn plug(&self) -> &'static str {
        match self.icon_set {
            IconSet::NerdFonts => "\u{f1e6}", // Plug
            IconSet::Unicode => "",
            IconSet::Emoji => "🔌",
            IconSet::Ascii => "[CONN]",
        }
    }

    #[must_use]
    pub fn circle_filled(&self) -> &'static str {
        match self.icon_set {
            IconSet::NerdFonts => "\u{f111}", // Circle
            IconSet::Unicode => "",
            IconSet::Emoji => "",
            IconSet::Ascii => "[x]",
        }
    }

    #[must_use]
    pub fn circle_empty(&self) -> &'static str {
        match self.icon_set {
            IconSet::NerdFonts => "\u{f1db}", // Circle
            IconSet::Unicode => "",
            IconSet::Emoji => "",
            IconSet::Ascii => "[ ]",
        }
    }

    #[must_use]
    pub fn inherits(&self) -> &'static str {
        match self.icon_set {
            IconSet::NerdFonts => "\u{f062}", // Arrow up
            IconSet::Unicode => "",
            IconSet::Emoji => "",
            IconSet::Ascii => "^",
        }
    }

    #[must_use]
    pub fn cog(&self) -> &'static str {
        match self.icon_set {
            IconSet::NerdFonts => "\u{f013}", // Cog/gear icon
            IconSet::Unicode => "",
            IconSet::Emoji => "⚙️",
            IconSet::Ascii => "[*]",
        }
    }
}

impl Default for Icons {
    fn default() -> Self {
        Self::new()
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_icon_set_detection() {
        let icon_set = IconSet::detect();
        assert!(matches!(
            icon_set,
            IconSet::NerdFonts | IconSet::Unicode | IconSet::Ascii
        ));
    }

    #[test]
    fn test_icons_creation() {
        let icons = Icons::new();
        assert!(!icons.folder().is_empty());
        assert!(!icons.sync().is_empty());
    }

    #[test]
    fn test_all_icon_sets_have_values() {
        for icon_set in [IconSet::NerdFonts, IconSet::Unicode, IconSet::Ascii] {
            let icons = Icons::with_icon_set(icon_set);
            assert!(!icons.folder().is_empty());
            assert!(!icons.sync().is_empty());
            assert!(!icons.profile().is_empty());
            assert!(!icons.package().is_empty());
            assert!(!icons.git().is_empty());
            assert!(!icons.success().is_empty());
            assert!(!icons.warning().is_empty());
            assert!(!icons.error().is_empty());
        }
    }
}