2017-08-20 19:29:23 +00:00
|
|
|
use ansi_term::{ANSIString, Style};
|
|
|
|
|
2018-12-07 23:43:31 +00:00
|
|
|
use crate::fs::fields as f;
|
2017-08-20 19:29:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
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"),
|
2017-08-26 13:30:33 +00:00
|
|
|
f::Type::BlockDevice => colours.block_device().paint("b"),
|
|
|
|
f::Type::CharDevice => colours.char_device().paint("c"),
|
2017-08-20 19:29:23 +00:00
|
|
|
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;
|
2017-08-26 13:30:33 +00:00
|
|
|
fn block_device(&self) -> Style;
|
|
|
|
fn char_device(&self) -> Style;
|
2017-08-20 19:29:23 +00:00
|
|
|
fn socket(&self) -> Style;
|
|
|
|
fn special(&self) -> Style;
|
|
|
|
}
|