Struct lscolors::LsColors

source ·
pub struct LsColors { /* private fields */ }
Expand description

Holds information about how different file system entries should be colorized / styled.

Implementations§

source§

impl LsColors

source

pub fn empty() -> Self

Construct an empty LsColors instance with no pre-defined styles.

source

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.

source

pub fn from_string(input: &str) -> Self

Creates a new LsColors instance from the given string.

source

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.

source

pub fn style_for<F: Colorable>(&self, file: &F) -> Option<&Style>

Get the ANSI style for a colorable path.

source

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.

source

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.

source

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.

source

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.

Trait Implementations§

source§

impl Clone for LsColors

source§

fn clone(&self) -> LsColors

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for LsColors

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for LsColors

source§

fn default() -> Self

Constructs a default LsColors instance with some default styles. See man dircolors for information about the default styles and colors.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.