diff --git a/src/lib.rs b/src/lib.rs index 899b51a..f759717 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -27,7 +27,7 @@ mod fs; pub mod style; -use std::collections::{HashMap, HashSet}; +use std::collections::HashMap; use std::env; use std::ffi::OsString; use std::fs::{DirEntry, FileType, Metadata}; @@ -143,6 +143,7 @@ impl Indicator { } type FileNameSuffix = String; +type Priority = usize; /// Iterator over the path components with their respective style. pub struct StyledComponents<'a> { @@ -221,29 +222,30 @@ impl Colorable for DirEntry { const LS_COLORS_DEFAULT: &str = "rs=0:lc=\x1b[:rc=m:cl=\x1b[K:ex=01;32:sg=30;43:su=37;41:di=01;34:st=37;44:ow=34;42:tw=30;42:ln=01;36:bd=01;33:cd=01;33:do=01;35:pi=33:so=01;35:"; #[derive(Default, Debug, Clone)] -struct SuffixMapping { - mappings: HashMap>, - case_sensitive: HashSet, +struct SuffixMappingEntry { + /// Keys are non-normalized suffixes(variants of the suffix), and values are + /// tuples containing an style and their priority. + /// We need to store the priority (the index of the entry in the env) here + /// because ls has an overriding mechanism. For example, + /// *.gz=01;33:*.tar.gz=01;31: and *.tar.gz=01;31:*.gz=01;33: are not the + /// same. + variants: HashMap, Priority)>, + // whether the variants are case sensitive or not + case_sensitive: bool, } -impl SuffixMapping { - fn push(&mut self, suffix: FileNameSuffix, style: Option