Skip to main content

koda_cli/widgets/
file_menu.rs

1//! File picker dropdown — thin wrapper around the generic dropdown.
2//!
3//! Appears when the user types `@` in the input. Filters live as
4//! the user continues typing the path.
5
6use super::dropdown::DropdownItem;
7
8/// A file path item for the dropdown.
9#[derive(Clone, Debug)]
10pub struct FileItem {
11    /// Relative path (e.g. "src/main.rs" or "koda-cli/").
12    pub path: String,
13    /// Whether this is a directory.
14    pub is_dir: bool,
15}
16
17impl DropdownItem for FileItem {
18    fn label(&self) -> &str {
19        &self.path
20    }
21    fn description(&self) -> String {
22        if self.is_dir {
23            "\u{1f4c1}".to_string() // 📁
24        } else {
25            String::new()
26        }
27    }
28    fn matches_filter(&self, _filter: &str) -> bool {
29        // Filtering is done externally via list_path_matches
30        // (fuzzy scoring). All items in the dropdown already match.
31        true
32    }
33}
34
35#[cfg(test)]
36mod tests {
37    use super::*;
38
39    #[test]
40    fn dir_shows_icon() {
41        let item = FileItem {
42            path: "src/".into(),
43            is_dir: true,
44        };
45        assert!(!item.description().is_empty());
46    }
47
48    #[test]
49    fn file_no_description() {
50        let item = FileItem {
51            path: "main.rs".into(),
52            is_dir: false,
53        };
54        assert!(item.description().is_empty());
55    }
56}