summaryrefslogtreecommitdiffstats
path: root/src/output
diff options
context:
space:
mode:
authorBenjamin Sago <ogham@bsago.me>2015-12-20 17:56:57 +1100
committerBenjamin Sago <ogham@bsago.me>2015-12-20 17:56:57 +1100
commit1b3492ce45552fa4335374ed6d3692992d00278b (patch)
tree116ce6b1f4374e6744f7aebee1f7bb0c179e1c84 /src/output
parent15cd67abe67ffeaef812f4080e1e35b06bf31784 (diff)
Move colours module into output
This commit moves the colours module to be a sub-module of the output one. This makes sense because finding which colour a certain file should be is only done during output, and (I think) the only places that the `Colours` struct's fields are ever queried is from the output module. The only casualty was that the `file_colour` from the filetype module had to be moved, as determining colours is no longer part of that module - only determining filetype is. So it now reflects its name!
Diffstat (limited to 'src/output')
-rw-r--r--src/output/colours.rs166
-rw-r--r--src/output/details.rs2
-rw-r--r--src/output/grid.rs8
-rw-r--r--src/output/lines.rs6
-rw-r--r--src/output/mod.rs29
5 files changed, 199 insertions, 12 deletions
diff --git a/src/output/colours.rs b/src/output/colours.rs
new file mode 100644
index 0000000..97ccd87
--- /dev/null
+++ b/src/output/colours.rs
@@ -0,0 +1,166 @@
+use ansi_term::Style;
+use ansi_term::Colour::{Red, Green, Yellow, Blue, Cyan, Purple, Fixed};
+
+
+#[derive(Clone, Copy, Debug, Default, PartialEq)]
+pub struct Colours {
+ pub filetypes: FileTypes,
+ pub perms: Permissions,
+ pub size: Size,
+ pub users: Users,
+ pub links: Links,
+ pub git: Git,
+
+ 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,
+}
+
+#[derive(Clone, Copy, Debug, Default, PartialEq)]
+pub struct FileTypes {
+ pub normal: Style,
+ pub directory: Style,
+ pub symlink: Style,
+ pub special: Style,
+ pub executable: Style,
+ 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,
+}
+
+#[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,
+
+ pub attribute: Style,
+}
+
+#[derive(Clone, Copy, Debug, Default, PartialEq)]
+pub struct Size {
+ pub numbers: Style,
+ pub unit: Style,
+}
+
+#[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,
+}
+
+#[derive(Clone, Copy, Debug, Default, PartialEq)]
+pub struct Git {
+ pub new: Style,
+ pub modified: Style,
+ pub deleted: Style,
+ pub renamed: Style,
+ pub typechange: Style,
+}
+
+impl Colours {
+ pub fn plain() -> Colours {
+ Colours::default()
+ }
+
+ pub fn colourful() -> Colours {
+ Colours {
+ filetypes: FileTypes {
+ normal: Style::default(),
+ directory: Blue.bold(),
+ symlink: Cyan.normal(),
+ special: Yellow.normal(),
+ executable: Green.bold(),
+ 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(),
+ temp: Fixed(244).normal(),
+ immediate: Yellow.bold().underline(),
+ compiled: Fixed(137).normal(),
+ },
+
+ perms: Permissions {
+ user_read: Yellow.bold(),
+ user_write: Red.bold(),
+ user_execute_file: Green.bold().underline(),
+ user_execute_other: Green.bold(),
+ group_read: Yellow.normal(),
+ group_write: Red.normal(),
+ group_execute: Green.normal(),
+ other_read: Yellow.normal(),
+ other_write: Red.normal(),
+ other_execute: Green.normal(),
+ attribute: Style::default(),
+ },
+
+ size: Size {
+ numbers: Green.bold(),
+ unit: Green.normal(),
+ },
+
+ users: Users {
+ user_you: Yellow.bold(),
+ user_someone_else: Style::default(),
+ group_yours: Yellow.bold(),
+ group_not_yours: Style::default(),
+ },
+
+ links: Links {
+ normal: Red.bold(),
+ multi_link_file: Red.on(Yellow),
+ },
+
+ git: Git {
+ new: Green.normal(),
+ modified: Blue.normal(),
+ deleted: Red.normal(),
+ renamed: Yellow.normal(),
+ typechange: Purple.normal(),
+ },
+
+ punctuation: Fixed(244).normal(),
+ date: Blue.normal(),
+ inode: Purple.normal(),
+ blocks: Cyan.normal(),
+ header: Style::default().underline(),
+
+ symlink_path: Cyan.normal(),
+ broken_arrow: Red.normal(),
+ broken_filename: Red.underline()
+ }
+ }
+}
diff --git a/src/output/details.rs b/src/output/details.rs
index 0b45b7b..0a65fe6 100644
--- a/src/output/details.rs
+++ b/src/output/details.rs
@@ -118,12 +118,12 @@ use std::string::ToString;
use std::ops::Add;
use std::iter::repeat;
-use colours::Colours;
use dir::Dir;
use feature::xattr::{Attribute, FileAttributes};
use file::fields as f;
use file::File;
use options::{FileFilter, RecurseOptions};
+use output::colours::Colours;
use output::column::{Alignment, Column, Columns, SizeFormat};
use output::cell::{TextCell, DisplayWidth};
diff --git a/src/output/grid.rs b/src/output/grid.rs
index 69001bf..f944fbb 100644
--- a/src/output/grid.rs
+++ b/src/output/grid.rs
@@ -1,9 +1,9 @@
-use colours::Colours;
+use term_grid as grid;
+
use file::File;
-use filetype::file_colour;
use output::DisplayWidth;
-
-use term_grid as grid;
+use output::colours::Colours;
+use super::file_colour;
#[derive(PartialEq, Debug, Copy, Clone)]
diff --git a/src/output/lines.rs b/src/output/lines.rs
index 39ef2c3..07c4351 100644
--- a/src/output/lines.rs
+++ b/src/output/lines.rs
@@ -1,9 +1,9 @@
-use colours::Colours;
-use file::File;
-
use ansi_term::ANSIStrings;
+use file::File;
+
use super::filename;
+use super::colours::Colours;
#[derive(Clone, Copy, Debug, PartialEq)]
diff --git a/src/output/mod.rs b/src/output/mod.rs
index d1c7e14..f095a79 100644
--- a/src/output/mod.rs
+++ b/src/output/mod.rs
@@ -1,14 +1,13 @@
use ansi_term::Style;
-use colours::Colours;
use file::File;
-use filetype::file_colour;
pub use self::cell::{TextCell, TextCellContents, DisplayWidth};
+pub use self::colours::Colours;
pub use self::details::Details;
+pub use self::grid_details::GridDetails;
pub use self::grid::Grid;
pub use self::lines::Lines;
-pub use self::grid_details::GridDetails;
mod grid;
pub mod details;
@@ -16,7 +15,7 @@ mod lines;
mod grid_details;
pub mod column;
mod cell;
-
+mod colours;
pub fn filename(file: File, colours: &Colours, links: bool) -> TextCellContents {
if links && file.is_link() {
@@ -49,3 +48,25 @@ fn symlink_filename(file: File, colours: &Colours) -> TextCellContents {
].into(),
}
}
+
+pub fn file_colour(colours: &Colours, file: &File) -> Style {
+ use filetype::FileTypes;
+
+ match file {
+ f if f.is_directory() => colours.filetypes.directory,
+ f if f.is_executable_file() => colours.filetypes.executable,
+ f if f.is_link() => colours.filetypes.symlink,
+ f if !f.is_file() => colours.filetypes.special,
+ f if f.is_immediate() => colours.filetypes.immediate,
+ f if f.is_image() => colours.filetypes.image,
+ f if f.is_video() => colours.filetypes.video,
+ f if f.is_music() => colours.filetypes.music,
+ f if f.is_lossless() => colours.filetypes.lossless,
+ f if f.is_crypto() => colours.filetypes.crypto,
+ f if f.is_document() => colours.filetypes.document,
+ f if f.is_compressed() => colours.filetypes.compressed,
+ f if f.is_temp() => colours.filetypes.temp,
+ f if f.is_compiled() => colours.filetypes.compiled,
+ _ => colours.filetypes.normal,
+ }
+} \ No newline at end of file