lx_cli/
sort.rs

1/// Handles sorting of file entries
2use crate::file_entry::FileEntry;
3use std::cmp::Ordering;
4
5/// Default sort: by file type (directory, executable, regular), then alphabetically by name (case-insensitive)
6pub fn sort_default(entries: &mut Vec<FileEntry>) {
7    entries.sort_by(|a, b| {
8        // First sort by type to maintain grouping
9        match a.get_file_type().cmp(&b.get_file_type()) {
10            Ordering::Equal => {
11                // Within same type, sort alphabetically by name (case-insensitive)
12                let a_name = a.path.to_string_lossy().to_lowercase();
13                let b_name = b.path.to_string_lossy().to_lowercase();
14                a_name.cmp(&b_name)
15            }
16            other => other,
17        }
18    });
19}