exa/src/output/render/filetype.rs
Benjamin Sago 276d18cf7c Give block and character devices different colours
There are now two device colours instead of one. Even though they’re both set to the same style for the default colour set, LS_COLORS allows the two to look different, so exa has to support it too.

It’s probably a good idea to support it anyway.
2017-08-26 14:30:33 +01:00

32 lines
1010 B
Rust

use ansi_term::{ANSIString, Style};
use fs::fields as f;
impl f::Type {
pub fn render<C: Colours>(&self, colours: &C) -> ANSIString<'static> {
match *self {
f::Type::File => colours.normal().paint("."),
f::Type::Directory => colours.directory().paint("d"),
f::Type::Pipe => colours.pipe().paint("|"),
f::Type::Link => colours.symlink().paint("l"),
f::Type::BlockDevice => colours.block_device().paint("b"),
f::Type::CharDevice => colours.char_device().paint("c"),
f::Type::Socket => colours.socket().paint("s"),
f::Type::Special => colours.special().paint("?"),
}
}
}
pub trait Colours {
fn normal(&self) -> Style;
fn directory(&self) -> Style;
fn pipe(&self) -> Style;
fn symlink(&self) -> Style;
fn block_device(&self) -> Style;
fn char_device(&self) -> Style;
fn socket(&self) -> Style;
fn special(&self) -> Style;
}