summaryrefslogtreecommitdiffstats
path: root/src/colours.rs
diff options
context:
space:
mode:
authorBen S <ogham@bsago.me>2015-05-09 23:57:18 +0100
committerBen S <ogham@bsago.me>2015-05-09 23:57:18 +0100
commit36116a142095d61ab7f601cb6efda03d2cb8d749 (patch)
tree8b4057bc23c5a92565610d9067077c87a6e1211b /src/colours.rs
parentda49b80c3525db7f0a0aae0fe2ac3e0a9a574cd3 (diff)
Add colours module, and disable them sometimes
Colours are now disabled when output is not to a terminal. Fixes #53! This required some internal restructuring - colours are now in their own object that gets passed around everywhere it's needed.
Diffstat (limited to 'src/colours.rs')
-rw-r--r--src/colours.rs52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/colours.rs b/src/colours.rs
new file mode 100644
index 0000000..46397a0
--- /dev/null
+++ b/src/colours.rs
@@ -0,0 +1,52 @@
+use ansi_term::Style;
+use ansi_term::Style::Plain;
+use ansi_term::Colour::{Red, Green, Yellow, Blue, Cyan, Fixed};
+
+use file::GREY;
+
+use std::default::Default;
+
+#[derive(Clone, Copy, Debug, Default, PartialEq)]
+pub struct Colours {
+ 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,
+}
+
+impl Colours {
+ pub fn plain() -> Colours {
+ Colours::default()
+ }
+
+ pub fn colourful() -> Colours {
+ Colours {
+ normal: Plain,
+ 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: GREY.normal(),
+ immediate: Yellow.bold().underline(),
+ compiled: Fixed(137).normal(),
+ }
+ }
+}