pub struct LsColors { /* private fields */ }
Expand description
Holds information about how different file system entries should be colorized / styled.
Implementations§
source§impl LsColors
impl LsColors
sourcepub fn from_env() -> Option<Self>
pub fn from_env() -> Option<Self>
Creates a new LsColors
instance from the LS_COLORS
environment
variable. The basis for this is a default style as constructed via the Default
implementation.
sourcepub fn from_string(input: &str) -> Self
pub fn from_string(input: &str) -> Self
Creates a new LsColors
instance from the given string.
sourcepub fn style_for_path<P: AsRef<Path>>(&self, path: P) -> Option<&Style>
pub fn style_for_path<P: AsRef<Path>>(&self, path: P) -> Option<&Style>
Get the ANSI style for a given path.
Note: this function calls Path::symlink_metadata
internally. If you already happen to
have the Metadata
available, use style_for_path_with_metadata
.
sourcepub fn style_for<F: Colorable>(&self, file: &F) -> Option<&Style>
pub fn style_for<F: Colorable>(&self, file: &F) -> Option<&Style>
Get the ANSI style for a colorable path.
sourcepub fn style_for_str(&self, file_str: &str) -> Option<&Style>
pub fn style_for_str(&self, file_str: &str) -> Option<&Style>
Get the ANSI style for a string. This does not have to be a valid filepath.
sourcepub fn style_for_path_with_metadata<P: AsRef<Path>>(
&self,
path: P,
metadata: Option<&Metadata>
) -> Option<&Style>
pub fn style_for_path_with_metadata<P: AsRef<Path>>( &self, path: P, metadata: Option<&Metadata> ) -> Option<&Style>
Get the ANSI style for a path, given the corresponding Metadata
struct.
Note: The Metadata
struct must have been acquired via Path::symlink_metadata
in
order to colorize symbolic links correctly.
sourcepub fn style_for_path_components<'a>(
&'a self,
path: &'a Path
) -> StyledComponents<'a> ⓘ
pub fn style_for_path_components<'a>( &'a self, path: &'a Path ) -> StyledComponents<'a> ⓘ
Get ANSI styles for each component of a given path. Components already include the path
separator symbol, if required. For a path like foo/bar/test.md
, this would return an
iterator over three pairs for the three path components foo/
, bar/
and test.md
together with their respective styles.
sourcepub fn style_for_indicator(&self, indicator: Indicator) -> Option<&Style>
pub fn style_for_indicator(&self, indicator: Indicator) -> Option<&Style>
Get the ANSI style for a certain Indicator
(regular file, directory, symlink, …). Note
that this function implements a fallback logic for some of the indicators (just like ls
).
For example, the style for mi
(missing file) falls back to or
(orphaned symbolic link)
if it has not been specified explicitly.