2015-05-09 22:57:18 +00:00
|
|
|
use ansi_term::Style;
|
2015-05-10 11:50:20 +00:00
|
|
|
use ansi_term::Colour::{Red, Green, Yellow, Blue, Cyan, Purple, Fixed};
|
2015-05-09 22:57:18 +00:00
|
|
|
|
2017-08-20 19:29:23 +00:00
|
|
|
use output::render;
|
|
|
|
|
2015-05-09 22:57:18 +00:00
|
|
|
|
|
|
|
#[derive(Clone, Copy, Debug, Default, PartialEq)]
|
|
|
|
pub struct Colours {
|
2016-10-30 15:50:09 +00:00
|
|
|
pub scale: bool,
|
|
|
|
|
2017-08-25 16:50:22 +00:00
|
|
|
pub filekinds: FileKinds,
|
2015-05-10 11:50:20 +00:00
|
|
|
pub filetypes: FileTypes,
|
|
|
|
pub perms: Permissions,
|
|
|
|
pub size: Size,
|
|
|
|
pub users: Users,
|
|
|
|
pub links: Links,
|
2015-05-10 16:57:21 +00:00
|
|
|
pub git: Git,
|
2015-05-10 11:50:20 +00:00
|
|
|
|
|
|
|
pub punctuation: Style,
|
|
|
|
pub date: Style,
|
|
|
|
pub inode: Style,
|
|
|
|
pub blocks: Style,
|
|
|
|
pub header: Style,
|
|
|
|
|
|
|
|
pub symlink_path: Style,
|
|
|
|
pub broken_arrow: Style,
|
|
|
|
pub broken_filename: Style,
|
2017-05-01 14:10:39 +00:00
|
|
|
pub control_char: Style,
|
2015-05-09 23:22:58 +00:00
|
|
|
}
|
|
|
|
|
2017-08-25 16:50:22 +00:00
|
|
|
// Colours for files depending on their filesystem type.
|
2015-05-09 23:22:58 +00:00
|
|
|
#[derive(Clone, Copy, Debug, Default, PartialEq)]
|
2017-08-25 16:50:22 +00:00
|
|
|
pub struct FileKinds {
|
2015-05-09 22:57:18 +00:00
|
|
|
pub normal: Style,
|
|
|
|
pub directory: Style,
|
2015-05-12 02:08:24 +00:00
|
|
|
pub symlink: Style,
|
2016-06-14 03:14:36 +00:00
|
|
|
pub pipe: Style,
|
2017-08-26 13:30:33 +00:00
|
|
|
pub block_device: Style,
|
|
|
|
pub char_device: Style,
|
2016-06-14 03:14:36 +00:00
|
|
|
pub socket: Style,
|
2015-05-12 02:08:24 +00:00
|
|
|
pub special: Style,
|
|
|
|
pub executable: Style,
|
2017-08-25 16:50:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Colours for files depending on their name or extension.
|
|
|
|
#[derive(Clone, Copy, Debug, Default, PartialEq)]
|
|
|
|
pub struct FileTypes {
|
2015-05-12 02:08:24 +00:00
|
|
|
pub image: Style,
|
|
|
|
pub video: Style,
|
|
|
|
pub music: Style,
|
|
|
|
pub lossless: Style,
|
|
|
|
pub crypto: Style,
|
|
|
|
pub document: Style,
|
|
|
|
pub compressed: Style,
|
|
|
|
pub temp: Style,
|
|
|
|
pub immediate: Style,
|
|
|
|
pub compiled: Style,
|
2015-05-09 22:57:18 +00:00
|
|
|
}
|
|
|
|
|
2015-05-10 11:50:20 +00:00
|
|
|
#[derive(Clone, Copy, Debug, Default, PartialEq)]
|
|
|
|
pub struct Permissions {
|
|
|
|
pub user_read: Style,
|
|
|
|
pub user_write: Style,
|
|
|
|
pub user_execute_file: Style,
|
|
|
|
pub user_execute_other: Style,
|
|
|
|
|
|
|
|
pub group_read: Style,
|
|
|
|
pub group_write: Style,
|
|
|
|
pub group_execute: Style,
|
|
|
|
|
|
|
|
pub other_read: Style,
|
|
|
|
pub other_write: Style,
|
|
|
|
pub other_execute: Style,
|
|
|
|
|
2017-05-30 14:31:24 +00:00
|
|
|
pub special_user_file: Style,
|
|
|
|
pub special_other: Style,
|
|
|
|
|
|
|
|
pub attribute: Style,
|
2015-05-10 11:50:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Copy, Debug, Default, PartialEq)]
|
|
|
|
pub struct Size {
|
|
|
|
pub numbers: Style,
|
|
|
|
pub unit: Style,
|
2017-05-16 19:54:39 +00:00
|
|
|
|
2017-05-19 08:20:47 +00:00
|
|
|
pub major: Style,
|
|
|
|
pub minor: Style,
|
|
|
|
|
2017-05-16 19:54:39 +00:00
|
|
|
pub scale_byte: Style,
|
|
|
|
pub scale_kilo: Style,
|
|
|
|
pub scale_mega: Style,
|
|
|
|
pub scale_giga: Style,
|
|
|
|
pub scale_huge: Style,
|
2015-05-10 11:50:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Copy, Debug, Default, PartialEq)]
|
|
|
|
pub struct Users {
|
|
|
|
pub user_you: Style,
|
|
|
|
pub user_someone_else: Style,
|
|
|
|
pub group_yours: Style,
|
|
|
|
pub group_not_yours: Style,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Copy, Debug, Default, PartialEq)]
|
|
|
|
pub struct Links {
|
|
|
|
pub normal: Style,
|
|
|
|
pub multi_link_file: Style,
|
|
|
|
}
|
|
|
|
|
2015-05-10 16:57:21 +00:00
|
|
|
#[derive(Clone, Copy, Debug, Default, PartialEq)]
|
|
|
|
pub struct Git {
|
|
|
|
pub new: Style,
|
|
|
|
pub modified: Style,
|
|
|
|
pub deleted: Style,
|
|
|
|
pub renamed: Style,
|
|
|
|
pub typechange: Style,
|
|
|
|
}
|
|
|
|
|
2015-05-09 22:57:18 +00:00
|
|
|
impl Colours {
|
|
|
|
pub fn plain() -> Colours {
|
|
|
|
Colours::default()
|
|
|
|
}
|
|
|
|
|
2016-10-30 15:50:09 +00:00
|
|
|
pub fn colourful(scale: bool) -> Colours {
|
2015-05-09 22:57:18 +00:00
|
|
|
Colours {
|
2016-10-30 15:50:09 +00:00
|
|
|
scale: scale,
|
|
|
|
|
2017-08-25 16:50:22 +00:00
|
|
|
filekinds: FileKinds {
|
2017-08-26 13:30:33 +00:00
|
|
|
normal: Style::default(),
|
|
|
|
directory: Blue.bold(),
|
|
|
|
symlink: Cyan.normal(),
|
|
|
|
pipe: Yellow.normal(),
|
|
|
|
block_device: Yellow.bold(),
|
|
|
|
char_device: Yellow.bold(),
|
|
|
|
socket: Red.bold(),
|
|
|
|
special: Yellow.normal(),
|
|
|
|
executable: Green.bold(),
|
2017-08-25 16:50:22 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
filetypes: FileTypes {
|
2015-05-09 23:22:58 +00:00
|
|
|
image: Fixed(133).normal(),
|
|
|
|
video: Fixed(135).normal(),
|
|
|
|
music: Fixed(92).normal(),
|
|
|
|
lossless: Fixed(93).normal(),
|
|
|
|
crypto: Fixed(109).normal(),
|
|
|
|
document: Fixed(105).normal(),
|
|
|
|
compressed: Red.normal(),
|
2015-05-10 17:03:15 +00:00
|
|
|
temp: Fixed(244).normal(),
|
2015-05-09 23:22:58 +00:00
|
|
|
immediate: Yellow.bold().underline(),
|
|
|
|
compiled: Fixed(137).normal(),
|
2015-05-10 11:50:20 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
perms: Permissions {
|
|
|
|
user_read: Yellow.bold(),
|
|
|
|
user_write: Red.bold(),
|
|
|
|
user_execute_file: Green.bold().underline(),
|
|
|
|
user_execute_other: Green.bold(),
|
2017-05-30 14:31:24 +00:00
|
|
|
|
2015-05-10 11:50:20 +00:00
|
|
|
group_read: Yellow.normal(),
|
|
|
|
group_write: Red.normal(),
|
|
|
|
group_execute: Green.normal(),
|
2017-05-30 14:31:24 +00:00
|
|
|
|
2015-05-10 11:50:20 +00:00
|
|
|
other_read: Yellow.normal(),
|
|
|
|
other_write: Red.normal(),
|
|
|
|
other_execute: Green.normal(),
|
2017-05-30 14:31:24 +00:00
|
|
|
|
|
|
|
special_user_file: Purple.normal(),
|
|
|
|
special_other: Purple.normal(),
|
|
|
|
|
2015-05-29 10:34:57 +00:00
|
|
|
attribute: Style::default(),
|
2015-05-10 11:50:20 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
size: Size {
|
|
|
|
numbers: Green.bold(),
|
|
|
|
unit: Green.normal(),
|
2017-05-16 19:54:39 +00:00
|
|
|
|
2017-05-19 08:20:47 +00:00
|
|
|
major: Green.bold(),
|
|
|
|
minor: Green.normal(),
|
|
|
|
|
2017-05-16 19:54:39 +00:00
|
|
|
scale_byte: Fixed(118).normal(),
|
|
|
|
scale_kilo: Fixed(190).normal(),
|
|
|
|
scale_mega: Fixed(226).normal(),
|
|
|
|
scale_giga: Fixed(220).normal(),
|
|
|
|
scale_huge: Fixed(214).normal(),
|
2015-05-10 11:50:20 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
users: Users {
|
|
|
|
user_you: Yellow.bold(),
|
2015-05-29 10:34:57 +00:00
|
|
|
user_someone_else: Style::default(),
|
2015-05-10 11:50:20 +00:00
|
|
|
group_yours: Yellow.bold(),
|
2015-05-29 10:34:57 +00:00
|
|
|
group_not_yours: Style::default(),
|
2015-05-10 11:50:20 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
links: Links {
|
|
|
|
normal: Red.bold(),
|
|
|
|
multi_link_file: Red.on(Yellow),
|
|
|
|
},
|
|
|
|
|
2015-05-10 16:57:21 +00:00
|
|
|
git: Git {
|
|
|
|
new: Green.normal(),
|
|
|
|
modified: Blue.normal(),
|
|
|
|
deleted: Red.normal(),
|
|
|
|
renamed: Yellow.normal(),
|
|
|
|
typechange: Purple.normal(),
|
|
|
|
},
|
|
|
|
|
2015-05-10 11:50:20 +00:00
|
|
|
punctuation: Fixed(244).normal(),
|
|
|
|
date: Blue.normal(),
|
|
|
|
inode: Purple.normal(),
|
|
|
|
blocks: Cyan.normal(),
|
2015-05-29 10:34:57 +00:00
|
|
|
header: Style::default().underline(),
|
2015-05-10 11:50:20 +00:00
|
|
|
|
|
|
|
symlink_path: Cyan.normal(),
|
|
|
|
broken_arrow: Red.normal(),
|
2017-05-01 14:10:39 +00:00
|
|
|
broken_filename: Red.underline(),
|
|
|
|
control_char: Red.normal(),
|
2015-05-09 22:57:18 +00:00
|
|
|
}
|
|
|
|
}
|
2017-08-20 19:29:23 +00:00
|
|
|
}
|
2016-10-30 15:09:36 +00:00
|
|
|
|
2017-08-20 19:29:23 +00:00
|
|
|
|
|
|
|
impl render::BlocksColours for Colours {
|
2017-08-26 13:30:33 +00:00
|
|
|
fn block_count(&self) -> Style { self.blocks }
|
|
|
|
fn no_blocks(&self) -> Style { self.punctuation }
|
2015-05-09 22:57:18 +00:00
|
|
|
}
|
2017-08-20 19:29:23 +00:00
|
|
|
|
|
|
|
impl render::FiletypeColours for Colours {
|
2017-08-26 13:30:33 +00:00
|
|
|
fn normal(&self) -> Style { self.filekinds.normal }
|
|
|
|
fn directory(&self) -> Style { self.filekinds.directory }
|
|
|
|
fn pipe(&self) -> Style { self.filekinds.pipe }
|
|
|
|
fn symlink(&self) -> Style { self.filekinds.symlink }
|
|
|
|
fn block_device(&self) -> Style { self.filekinds.block_device }
|
|
|
|
fn char_device(&self) -> Style { self.filekinds.char_device }
|
|
|
|
fn socket(&self) -> Style { self.filekinds.socket }
|
|
|
|
fn special(&self) -> Style { self.filekinds.special }
|
2017-08-20 19:29:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl render::GitColours for Colours {
|
2017-08-26 13:30:33 +00:00
|
|
|
fn not_modified(&self) -> Style { self.punctuation }
|
|
|
|
fn new(&self) -> Style { self.git.new }
|
|
|
|
fn modified(&self) -> Style { self.git.modified }
|
|
|
|
fn deleted(&self) -> Style { self.git.deleted }
|
|
|
|
fn renamed(&self) -> Style { self.git.renamed }
|
|
|
|
fn type_change(&self) -> Style { self.git.typechange }
|
2017-08-20 19:29:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl render::GroupColours for Colours {
|
2017-08-26 13:30:33 +00:00
|
|
|
fn yours(&self) -> Style { self.users.group_yours }
|
|
|
|
fn not_yours(&self) -> Style { self.users.group_not_yours }
|
2017-08-20 19:29:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl render::LinksColours for Colours {
|
2017-08-26 13:30:33 +00:00
|
|
|
fn normal(&self) -> Style { self.links.normal }
|
|
|
|
fn multi_link_file(&self) -> Style { self.links.multi_link_file }
|
2017-08-20 19:29:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl render::PermissionsColours for Colours {
|
2017-08-26 13:30:33 +00:00
|
|
|
fn dash(&self) -> Style { self.punctuation }
|
|
|
|
fn user_read(&self) -> Style { self.perms.user_read }
|
|
|
|
fn user_write(&self) -> Style { self.perms.user_write }
|
|
|
|
fn user_execute_file(&self) -> Style { self.perms.user_execute_file }
|
|
|
|
fn user_execute_other(&self) -> Style { self.perms.user_execute_other }
|
|
|
|
fn group_read(&self) -> Style { self.perms.group_read }
|
|
|
|
fn group_write(&self) -> Style { self.perms.group_write }
|
|
|
|
fn group_execute(&self) -> Style { self.perms.group_execute }
|
|
|
|
fn other_read(&self) -> Style { self.perms.other_read }
|
|
|
|
fn other_write(&self) -> Style { self.perms.other_write }
|
|
|
|
fn other_execute(&self) -> Style { self.perms.other_execute }
|
|
|
|
fn special_user_file(&self) -> Style { self.perms.special_user_file }
|
|
|
|
fn special_other(&self) -> Style { self.perms.special_other }
|
|
|
|
fn attribute(&self) -> Style { self.perms.attribute }
|
2017-08-20 19:29:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl render::SizeColours for Colours {
|
2017-08-26 13:30:33 +00:00
|
|
|
fn size(&self, size: u64) -> Style {
|
|
|
|
if self.scale {
|
|
|
|
if size < 1024 {
|
|
|
|
self.size.scale_byte
|
|
|
|
}
|
|
|
|
else if size < 1024 * 1024 {
|
|
|
|
self.size.scale_kilo
|
|
|
|
}
|
|
|
|
else if size < 1024 * 1024 * 1024 {
|
|
|
|
self.size.scale_mega
|
|
|
|
}
|
|
|
|
else if size < 1024 * 1024 * 1024 * 1024 {
|
|
|
|
self.size.scale_giga
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
self.size.scale_huge
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
self.size.numbers
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn unit(&self) -> Style { self.size.unit }
|
|
|
|
fn no_size(&self) -> Style { self.punctuation }
|
|
|
|
fn major(&self) -> Style { self.size.major }
|
|
|
|
fn comma(&self) -> Style { self.punctuation }
|
|
|
|
fn minor(&self) -> Style { self.size.minor }
|
2017-08-20 19:29:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl render::UserColours for Colours {
|
2017-08-26 13:30:33 +00:00
|
|
|
fn you(&self) -> Style { self.users.user_you }
|
|
|
|
fn someone_else(&self) -> Style { self.users.user_someone_else }
|
2017-08-20 19:29:23 +00:00
|
|
|
}
|
|
|
|
|