git-iris 2.0.8

AI-powered Git workflow assistant for smart commits, code reviews, changelogs, and release notes
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
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
//! File tree component for Iris Studio
//!
//! Hierarchical file browser with git status indicators.

use ratatui::Frame;
use ratatui::layout::Rect;
use ratatui::style::{Modifier, Style};
use ratatui::text::{Line, Span};
use ratatui::widgets::{
    Block, Borders, Paragraph, Scrollbar, ScrollbarOrientation, ScrollbarState,
};
use std::collections::HashSet;
use std::path::{Path, PathBuf};
use unicode_width::UnicodeWidthStr;

use crate::studio::theme;
use crate::studio::utils::truncate_width;

// ═══════════════════════════════════════════════════════════════════════════════
// Git Status
// ═══════════════════════════════════════════════════════════════════════════════

/// Git status for a file
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum FileGitStatus {
    #[default]
    Normal,
    Staged,
    Modified,
    Untracked,
    Deleted,
    Renamed,
    Conflict,
}

impl FileGitStatus {
    /// Get the indicator character for this status
    #[must_use]
    pub fn indicator(self) -> &'static str {
        match self {
            Self::Normal => " ",
            Self::Staged => "",
            Self::Modified => "",
            Self::Untracked => "?",
            Self::Deleted => "",
            Self::Renamed => "",
            Self::Conflict => "!",
        }
    }

    /// Get the style for this status
    #[must_use]
    pub fn style(self) -> Style {
        match self {
            Self::Normal => theme::dimmed(),
            Self::Staged => theme::git_staged(),
            Self::Modified => theme::git_modified(),
            Self::Untracked => theme::git_untracked(),
            Self::Deleted => theme::git_deleted(),
            Self::Renamed => theme::git_staged(),
            Self::Conflict => theme::error(),
        }
    }
}

// ═══════════════════════════════════════════════════════════════════════════════
// Tree Node
// ═══════════════════════════════════════════════════════════════════════════════

/// A node in the file tree
#[derive(Debug, Clone)]
pub struct TreeNode {
    /// File or directory name
    pub name: String,
    /// Full path from repository root
    pub path: PathBuf,
    /// Is this a directory?
    pub is_dir: bool,
    /// Git status (for files)
    pub git_status: FileGitStatus,
    /// Depth in tree (for indentation)
    pub depth: usize,
    /// Children (for directories)
    pub children: Vec<TreeNode>,
}

impl TreeNode {
    /// Create a new file node
    pub fn file(name: impl Into<String>, path: impl Into<PathBuf>, depth: usize) -> Self {
        Self {
            name: name.into(),
            path: path.into(),
            is_dir: false,
            git_status: FileGitStatus::Normal,
            depth,
            children: Vec::new(),
        }
    }

    /// Create a new directory node
    pub fn dir(name: impl Into<String>, path: impl Into<PathBuf>, depth: usize) -> Self {
        Self {
            name: name.into(),
            path: path.into(),
            is_dir: true,
            git_status: FileGitStatus::Normal,
            depth,
            children: Vec::new(),
        }
    }

    /// Set git status
    #[must_use]
    pub fn with_status(mut self, status: FileGitStatus) -> Self {
        self.git_status = status;
        self
    }

    /// Add a child node
    pub fn add_child(&mut self, child: TreeNode) {
        self.children.push(child);
    }

    /// Sort children (directories first, then alphabetically)
    pub fn sort_children(&mut self) {
        self.children.sort_by(|a, b| match (a.is_dir, b.is_dir) {
            (true, false) => std::cmp::Ordering::Less,
            (false, true) => std::cmp::Ordering::Greater,
            _ => a.name.to_lowercase().cmp(&b.name.to_lowercase()),
        });
        for child in &mut self.children {
            child.sort_children();
        }
    }
}

// ═══════════════════════════════════════════════════════════════════════════════
// Flattened Entry (for rendering)
// ═══════════════════════════════════════════════════════════════════════════════

/// A flattened view of the tree for rendering
#[derive(Debug, Clone)]
pub struct FlatEntry {
    pub name: String,
    pub path: PathBuf,
    pub is_dir: bool,
    pub git_status: FileGitStatus,
    pub depth: usize,
    pub is_expanded: bool,
    pub has_children: bool,
}

// ═══════════════════════════════════════════════════════════════════════════════
// File Tree State
// ═══════════════════════════════════════════════════════════════════════════════

/// File tree widget state
#[derive(Debug, Clone)]
pub struct FileTreeState {
    /// Root nodes of the tree
    root: Vec<TreeNode>,
    /// Expanded directories (by path)
    expanded: HashSet<PathBuf>,
    /// Currently selected index in flat view
    selected: usize,
    /// Scroll offset
    scroll_offset: usize,
    /// Cached flat view
    flat_cache: Vec<FlatEntry>,
    /// Cache is dirty flag
    cache_dirty: bool,
}

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

impl FileTreeState {
    /// Create new empty file tree state
    #[must_use]
    pub fn new() -> Self {
        Self {
            root: Vec::new(),
            expanded: HashSet::new(),
            selected: 0,
            scroll_offset: 0,
            flat_cache: Vec::new(),
            cache_dirty: true,
        }
    }

    /// Check if tree is empty
    #[must_use]
    pub fn is_empty(&self) -> bool {
        self.root.is_empty()
    }

    /// Set root nodes
    pub fn set_root(&mut self, root: Vec<TreeNode>) {
        self.root = root;
        self.cache_dirty = true;
        self.selected = 0;
        self.scroll_offset = 0;
    }

    /// Build tree from a list of file paths
    #[must_use]
    pub fn from_paths(paths: &[PathBuf], git_statuses: &[(PathBuf, FileGitStatus)]) -> Self {
        let mut state = Self::new();
        let mut root_nodes: Vec<TreeNode> = Vec::new();

        // Build status lookup
        let status_map: std::collections::HashMap<_, _> = git_statuses.iter().cloned().collect();

        for path in paths {
            let components: Vec<_> = path.components().collect();
            insert_path(&mut root_nodes, &components, 0, path, &status_map);
        }

        // Sort all nodes
        for node in &mut root_nodes {
            node.sort_children();
        }

        // Sort root level
        root_nodes.sort_by(|a, b| match (a.is_dir, b.is_dir) {
            (true, false) => std::cmp::Ordering::Less,
            (false, true) => std::cmp::Ordering::Greater,
            _ => a.name.to_lowercase().cmp(&b.name.to_lowercase()),
        });

        state.root = root_nodes;
        state.cache_dirty = true;
        // Auto-expand first 2 levels for visibility
        state.expand_to_depth(2);
        state
    }

    /// Get flat view (rebuilds cache if needed)
    pub fn flat_view(&mut self) -> &[FlatEntry] {
        if self.cache_dirty {
            self.rebuild_cache();
        }
        &self.flat_cache
    }

    /// Rebuild the flat cache
    fn rebuild_cache(&mut self) {
        self.flat_cache.clear();
        let root_clone = self.root.clone();
        for node in &root_clone {
            self.flatten_node(node);
        }
        self.cache_dirty = false;
    }

    /// Flatten a node into the cache
    fn flatten_node(&mut self, node: &TreeNode) {
        let is_expanded = self.expanded.contains(&node.path);

        self.flat_cache.push(FlatEntry {
            name: node.name.clone(),
            path: node.path.clone(),
            is_dir: node.is_dir,
            git_status: node.git_status,
            depth: node.depth,
            is_expanded,
            has_children: !node.children.is_empty(),
        });

        if is_expanded {
            let children = node.children.clone();
            for child in &children {
                self.flatten_node(child);
            }
        }
    }

    /// Get selected entry
    pub fn selected_entry(&mut self) -> Option<FlatEntry> {
        self.ensure_cache();
        self.flat_cache.get(self.selected).cloned()
    }

    /// Ensure cache is up to date
    fn ensure_cache(&mut self) {
        if self.cache_dirty {
            self.rebuild_cache();
        }
    }

    /// Get selected path
    pub fn selected_path(&mut self) -> Option<PathBuf> {
        self.selected_entry().map(|e| e.path)
    }

    /// Select an entry by path
    pub fn select_path(&mut self, path: &Path) -> bool {
        let selected = self.flat_view().iter().position(|entry| entry.path == path);

        if let Some(index) = selected {
            self.selected = index;
            self.ensure_visible();
            true
        } else {
            false
        }
    }

    /// Move selection up
    pub fn select_prev(&mut self) {
        if self.selected > 0 {
            self.selected -= 1;
            self.ensure_visible();
        }
    }

    /// Move selection down
    pub fn select_next(&mut self) {
        let len = self.flat_view().len();
        if self.selected + 1 < len {
            self.selected += 1;
            self.ensure_visible();
        }
    }

    /// Jump to first item
    pub fn select_first(&mut self) {
        self.selected = 0;
        self.scroll_offset = 0;
    }

    /// Jump to last item
    pub fn select_last(&mut self) {
        let len = self.flat_view().len();
        if len > 0 {
            self.selected = len - 1;
        }
    }

    /// Page up
    pub fn page_up(&mut self, page_size: usize) {
        self.selected = self.selected.saturating_sub(page_size);
        self.ensure_visible();
    }

    /// Page down
    pub fn page_down(&mut self, page_size: usize) {
        let len = self.flat_view().len();
        self.selected = (self.selected + page_size).min(len.saturating_sub(1));
        self.ensure_visible();
    }

    /// Toggle expansion of selected item
    pub fn toggle_expand(&mut self) {
        if let Some(entry) = self.selected_entry()
            && entry.is_dir
        {
            if self.expanded.contains(&entry.path) {
                self.expanded.remove(&entry.path);
            } else {
                self.expanded.insert(entry.path);
            }
            self.cache_dirty = true;
        }
    }

    /// Expand selected directory
    pub fn expand(&mut self) {
        if let Some(entry) = self.selected_entry()
            && entry.is_dir
            && !self.expanded.contains(&entry.path)
        {
            self.expanded.insert(entry.path);
            self.cache_dirty = true;
        }
    }

    /// Collapse selected directory (or parent)
    pub fn collapse(&mut self) {
        if let Some(entry) = self.selected_entry() {
            if entry.is_dir && self.expanded.contains(&entry.path) {
                self.expanded.remove(&entry.path);
                self.cache_dirty = true;
            } else if entry.depth > 0 {
                // Find and select parent
                let parent_path = entry.path.parent().map(Path::to_path_buf);
                if let Some(parent) = parent_path {
                    self.expanded.remove(&parent);
                    self.cache_dirty = true;
                    // Find parent in flat view and select it
                    let flat = self.flat_view();
                    for (i, e) in flat.iter().enumerate() {
                        if e.path == parent {
                            self.selected = i;
                            break;
                        }
                    }
                }
            }
        }
    }

    /// Expand all directories
    pub fn expand_all(&mut self) {
        self.expand_all_recursive(&self.root.clone());
        self.cache_dirty = true;
    }

    fn expand_all_recursive(&mut self, nodes: &[TreeNode]) {
        for node in nodes {
            if node.is_dir {
                self.expanded.insert(node.path.clone());
                self.expand_all_recursive(&node.children);
            }
        }
    }

    /// Collapse all directories
    pub fn collapse_all(&mut self) {
        self.expanded.clear();
        self.cache_dirty = true;
        self.selected = 0;
    }

    /// Expand directories up to a certain depth
    pub fn expand_to_depth(&mut self, max_depth: usize) {
        self.expand_to_depth_recursive(&self.root.clone(), 0, max_depth);
        self.cache_dirty = true;
    }

    fn expand_to_depth_recursive(
        &mut self,
        nodes: &[TreeNode],
        current_depth: usize,
        max_depth: usize,
    ) {
        if current_depth >= max_depth {
            return;
        }
        for node in nodes {
            if node.is_dir {
                self.expanded.insert(node.path.clone());
                self.expand_to_depth_recursive(&node.children, current_depth + 1, max_depth);
            }
        }
    }

    /// Ensure selected item is visible (stub for future scroll viewport tracking)
    #[allow(clippy::unused_self)]
    fn ensure_visible(&mut self) {
        // Will be adjusted based on render area height
    }

    /// Update scroll offset based on area height
    pub fn update_scroll(&mut self, visible_height: usize) {
        if visible_height == 0 {
            return;
        }

        // Ensure selected is within scroll view
        if self.selected < self.scroll_offset {
            self.scroll_offset = self.selected;
        } else if self.selected >= self.scroll_offset + visible_height {
            self.scroll_offset = self.selected - visible_height + 1;
        }
    }

    /// Get current scroll offset
    #[must_use]
    pub fn scroll_offset(&self) -> usize {
        self.scroll_offset
    }

    /// Get selected index
    #[must_use]
    pub fn selected_index(&self) -> usize {
        self.selected
    }

    /// Select an item by visible row (for mouse clicks)
    /// Returns true if selection changed, false otherwise
    pub fn select_by_row(&mut self, row: usize) -> bool {
        let flat_len = self.flat_view().len();
        let target_index = self.scroll_offset + row;

        if target_index < flat_len && target_index != self.selected {
            self.selected = target_index;
            true
        } else {
            false
        }
    }

    /// Check if the clicked row matches the currently selected item
    /// Used for double-click detection
    #[must_use]
    pub fn is_row_selected(&self, row: usize) -> bool {
        let target_index = self.scroll_offset + row;
        target_index == self.selected
    }

    /// Handle mouse click at a specific row within the visible area.
    /// Returns a tuple of (`selection_changed`, `is_directory`) for the caller to handle.
    pub fn handle_click(&mut self, row: usize) -> (bool, bool) {
        let flat_len = self.flat_view().len();
        let target_index = self.scroll_offset + row;

        if target_index >= flat_len {
            return (false, false);
        }

        let was_selected = target_index == self.selected;
        let is_dir = self.flat_cache.get(target_index).is_some_and(|e| e.is_dir);

        if !was_selected {
            self.selected = target_index;
        }

        (!was_selected, is_dir)
    }
}

/// Helper to insert a path into the tree structure
fn insert_path(
    nodes: &mut Vec<TreeNode>,
    components: &[std::path::Component<'_>],
    depth: usize,
    full_path: &Path,
    status_map: &std::collections::HashMap<PathBuf, FileGitStatus>,
) {
    if components.is_empty() {
        return;
    }

    let name = components[0].as_os_str().to_string_lossy().to_string();
    let is_last = components.len() == 1;

    // Build path up to this directory (take first depth+1 components from full_path)
    let current_path: PathBuf = full_path.components().take(depth + 1).collect();

    // Find or create node
    let node_idx = nodes.iter().position(|n| n.name == name);

    if is_last {
        // This is a file
        let status = status_map.get(full_path).copied().unwrap_or_default();
        if node_idx.is_none() {
            nodes.push(TreeNode::file(name, full_path, depth).with_status(status));
        }
    } else {
        // This is a directory
        let idx = if let Some(idx) = node_idx {
            idx
        } else {
            nodes.push(TreeNode::dir(name, current_path, depth));
            nodes.len() - 1
        };

        insert_path(
            &mut nodes[idx].children,
            &components[1..],
            depth + 1,
            full_path,
            status_map,
        );
    }
}

// ═══════════════════════════════════════════════════════════════════════════════
// Rendering
// ═══════════════════════════════════════════════════════════════════════════════

/// Render the file tree widget
pub fn render_file_tree(
    frame: &mut Frame,
    area: Rect,
    state: &mut FileTreeState,
    title: &str,
    focused: bool,
) {
    let block = Block::default()
        .title(format!(" {} ", title))
        .borders(Borders::ALL)
        .border_style(if focused {
            theme::focused_border()
        } else {
            theme::unfocused_border()
        });

    let inner = block.inner(area);
    frame.render_widget(block, area);

    if inner.height == 0 || inner.width == 0 {
        return;
    }

    let visible_height = inner.height as usize;
    state.update_scroll(visible_height);

    // Get values we need before borrowing flat view
    let scroll_offset = state.scroll_offset();
    let selected = state.selected_index();

    // Now get the flat view
    let flat = state.flat_view().to_vec(); // Clone to avoid borrow issues
    let flat_len = flat.len();

    let lines: Vec<Line> = flat
        .iter()
        .enumerate()
        .skip(scroll_offset)
        .take(visible_height)
        .map(|(i, entry)| {
            let is_selected = i == selected;
            render_entry(entry, is_selected, inner.width as usize)
        })
        .collect();

    let paragraph = Paragraph::new(lines);
    frame.render_widget(paragraph, inner);

    // Render scrollbar if needed
    if flat_len > visible_height {
        let scrollbar = Scrollbar::new(ScrollbarOrientation::VerticalRight)
            .begin_symbol(None)
            .end_symbol(None);

        let mut scrollbar_state = ScrollbarState::new(flat_len).position(scroll_offset);

        frame.render_stateful_widget(
            scrollbar,
            area.inner(ratatui::layout::Margin {
                vertical: 1,
                horizontal: 0,
            }),
            &mut scrollbar_state,
        );
    }
}

/// Render a single tree entry
fn render_entry(entry: &FlatEntry, is_selected: bool, width: usize) -> Line<'static> {
    let indent = "  ".repeat(entry.depth);

    // Icon with nice Unicode symbols
    let icon = if entry.is_dir {
        if entry.is_expanded { "" } else { "" }
    } else {
        get_file_icon(&entry.name)
    };

    // Git status indicator with Unicode symbols - positioned at start for visibility
    // Uses theme git_* styles for consistent, harmonized colors
    let (status_indicator, status_style) = match entry.git_status {
        FileGitStatus::Staged => ("", theme::git_staged().add_modifier(Modifier::BOLD)),
        FileGitStatus::Modified => ("", theme::git_modified()),
        FileGitStatus::Untracked => ("", theme::git_untracked()),
        FileGitStatus::Deleted => ("", theme::git_deleted()),
        FileGitStatus::Renamed => ("", theme::git_staged()),
        FileGitStatus::Conflict => ("", theme::error().add_modifier(Modifier::BOLD)),
        FileGitStatus::Normal => (" ", Style::default()),
    };

    // Selection marker
    let marker = if is_selected { "" } else { " " };
    let marker_style = if is_selected {
        Style::default()
            .fg(theme::accent_primary())
            .add_modifier(Modifier::BOLD)
    } else {
        Style::default()
    };

    // Name style - color coded by git status using theme git_* styles
    let name_style = if is_selected {
        // When selected, use git status color with selection background
        match entry.git_status {
            FileGitStatus::Staged => theme::git_staged()
                .bg(theme::bg_highlight_color())
                .add_modifier(Modifier::BOLD),
            FileGitStatus::Modified => theme::git_modified().bg(theme::bg_highlight_color()),
            FileGitStatus::Deleted => theme::git_deleted()
                .bg(theme::bg_highlight_color())
                .add_modifier(Modifier::DIM),
            FileGitStatus::Untracked => theme::git_untracked().bg(theme::bg_highlight_color()),
            FileGitStatus::Conflict => theme::error()
                .bg(theme::bg_highlight_color())
                .add_modifier(Modifier::BOLD),
            _ => theme::selected(),
        }
    } else if entry.is_dir {
        Style::default()
            .fg(theme::accent_secondary())
            .add_modifier(Modifier::BOLD)
    } else {
        // Color filename by git status using theme styles
        match entry.git_status {
            FileGitStatus::Staged => theme::git_staged().add_modifier(Modifier::BOLD),
            FileGitStatus::Modified => theme::git_modified(),
            FileGitStatus::Deleted => theme::git_deleted().add_modifier(Modifier::DIM),
            FileGitStatus::Untracked => theme::git_untracked(),
            FileGitStatus::Renamed => theme::git_staged(),
            FileGitStatus::Conflict => theme::error().add_modifier(Modifier::BOLD),
            FileGitStatus::Normal => Style::default().fg(theme::text_primary_color()),
        }
    };

    // Icon style matches name for cohesion - use theme git_* styles
    let icon_style = if entry.is_dir {
        Style::default().fg(theme::accent_secondary())
    } else {
        match entry.git_status {
            FileGitStatus::Staged => theme::git_staged(),
            FileGitStatus::Modified => theme::git_modified(),
            FileGitStatus::Deleted => theme::git_deleted(),
            FileGitStatus::Untracked => theme::git_untracked(),
            _ => Style::default().fg(theme::text_dim_color()),
        }
    };

    // Calculate available width for name using unicode width
    // Format: status (1) + ">" (1) + " " (1) + indent + icon (1) + " " (1) + name
    let fixed_width = 1 + 1 + 1 + indent.width() + 1 + 1;
    let max_name_width = width.saturating_sub(fixed_width);

    // Truncate name if needed (using unicode width)
    let display_name = truncate_width(&entry.name, max_name_width);

    Line::from(vec![
        Span::styled(status_indicator, status_style),
        Span::styled(marker, marker_style),
        Span::raw(" "),
        Span::raw(indent),
        Span::styled(format!("{} ", icon), icon_style),
        Span::styled(display_name, name_style),
    ])
}

/// Get icon for file based on extension (Unicode symbols, no emoji)
fn get_file_icon(name: &str) -> &'static str {
    // Check for special filenames first
    let lower_name = name.to_lowercase();
    if lower_name == "cargo.toml" || lower_name == "cargo.lock" {
        return "";
    }
    if lower_name.starts_with("readme") {
        return "";
    }
    if lower_name.starts_with("license") {
        return "§";
    }
    if lower_name.starts_with(".git") {
        return "";
    }
    if lower_name == "dockerfile" || lower_name.starts_with("docker-compose") {
        return "";
    }
    if lower_name == "makefile" {
        return "";
    }

    let ext = name.rsplit('.').next().unwrap_or("");
    match ext.to_lowercase().as_str() {
        // Rust
        "rs" => "",
        // Config files
        "toml" => "",
        "yaml" | "yml" => "",
        "json" => "",
        "xml" => "",
        "ini" | "cfg" | "conf" => "",
        // Documentation
        "md" | "mdx" => "",
        "txt" => "",
        "pdf" => "",
        // Web
        "html" | "htm" => "",
        "css" | "scss" | "sass" | "less" => "",
        "js" | "mjs" | "cjs" => "",
        "jsx" => "",
        "ts" | "mts" | "cts" => "",
        "tsx" => "",
        "vue" => "",
        "svelte" => "",
        // Programming languages
        "py" | "pyi" => "",
        "go" => "",
        "rb" => "",
        "java" | "class" | "jar" => "",
        "kt" | "kts" => "",
        "swift" => "",
        "c" | "h" => "",
        "cpp" | "cc" | "cxx" | "hpp" | "hxx" => "",
        "cs" => "",
        "php" => "",
        "lua" => "",
        "r" => "",
        "sql" => "",
        // Shell
        "sh" | "bash" | "zsh" | "fish" => "",
        "ps1" | "psm1" => "",
        // Data
        "csv" => "",
        "db" | "sqlite" | "sqlite3" => "",
        // Images
        "png" | "jpg" | "jpeg" | "gif" | "svg" | "ico" | "webp" => "",
        // Archives
        "zip" | "tar" | "gz" | "rar" | "7z" => "",
        // Lock files
        "lock" => "",
        // Git
        "gitignore" | "gitattributes" | "gitmodules" => "",
        // Env
        "env" | "env.local" | "env.development" | "env.production" => "",
        // Default
        _ => "",
    }
}