From 5f497da85d2a21a4fc6c529868efe8ed2d8120bd Mon Sep 17 00:00:00 2001 From: Benjamin Sago Date: Sun, 21 May 2017 16:59:02 +0100 Subject: [PATCH] This actually makes the Git part big enough MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …for its own module. --- src/output/render/git.rs | 80 ++++++++++++++++++++++++++++++++++++++++ src/output/render/mod.rs | 80 +--------------------------------------- 2 files changed, 82 insertions(+), 78 deletions(-) create mode 100644 src/output/render/git.rs diff --git a/src/output/render/git.rs b/src/output/render/git.rs new file mode 100644 index 0000000..20080bd --- /dev/null +++ b/src/output/render/git.rs @@ -0,0 +1,80 @@ +use output::cell::{TextCell, DisplayWidth}; +use output::colours::Colours; +use fs::fields as f; + + +impl f::Git { + pub fn render(&self, colours: &Colours) -> TextCell { + let git_char = |status| match status { + &f::GitStatus::NotModified => colours.punctuation.paint("-"), + &f::GitStatus::New => colours.git.new.paint("N"), + &f::GitStatus::Modified => colours.git.modified.paint("M"), + &f::GitStatus::Deleted => colours.git.deleted.paint("D"), + &f::GitStatus::Renamed => colours.git.renamed.paint("R"), + &f::GitStatus::TypeChange => colours.git.typechange.paint("T"), + }; + + TextCell { + width: DisplayWidth::from(2), + contents: vec![ + git_char(&self.staged), + git_char(&self.unstaged) + ].into(), + } + } +} + + +#[cfg(test)] +pub mod test { + use output::details::Details; + use output::cell::{TextCell, DisplayWidth}; + use fs::fields as f; + + use ansi_term::Colour::*; + + + #[test] + fn git_blank() { + let mut details = Details::default(); + details.colours.punctuation = Fixed(44).normal(); + + let stati = f::Git { + staged: f::GitStatus::NotModified, + unstaged: f::GitStatus::NotModified, + }; + + let expected = TextCell { + width: DisplayWidth::from(2), + contents: vec![ + Fixed(44).paint("-"), + Fixed(44).paint("-"), + ].into(), + }; + + assert_eq!(expected, stati.render(&details.colours).into()) + } + + + #[test] + fn git_new_changed() { + let mut details = Details::default(); + details.colours.git.new = Red.normal(); + details.colours.git.modified = Purple.normal(); + + let stati = f::Git { + staged: f::GitStatus::New, + unstaged: f::GitStatus::Modified, + }; + + let expected = TextCell { + width: DisplayWidth::from(2), + contents: vec![ + Red.paint("N"), + Purple.paint("M"), + ].into(), + }; + + assert_eq!(expected, stati.render(&details.colours).into()) + } +} diff --git a/src/output/render/mod.rs b/src/output/render/mod.rs index 27ff95c..20acde3 100644 --- a/src/output/render/mod.rs +++ b/src/output/render/mod.rs @@ -1,9 +1,10 @@ +mod git; mod groups; mod permissions; mod size; mod users; -use output::cell::{TextCell, DisplayWidth}; +use output::cell::TextCell; use output::colours::Colours; use fs::fields as f; @@ -75,80 +76,3 @@ impl f::Time { } } } - - -impl f::Git { - pub fn render(&self, colours: &Colours) -> TextCell { - let git_char = |status| match status { - &f::GitStatus::NotModified => colours.punctuation.paint("-"), - &f::GitStatus::New => colours.git.new.paint("N"), - &f::GitStatus::Modified => colours.git.modified.paint("M"), - &f::GitStatus::Deleted => colours.git.deleted.paint("D"), - &f::GitStatus::Renamed => colours.git.renamed.paint("R"), - &f::GitStatus::TypeChange => colours.git.typechange.paint("T"), - }; - - TextCell { - width: DisplayWidth::from(2), - contents: vec![ - git_char(&self.staged), - git_char(&self.unstaged) - ].into(), - } - } -} - - -#[cfg(test)] -pub mod test { - use output::details::Details; - use output::cell::{TextCell, DisplayWidth}; - use fs::fields as f; - - use ansi_term::Colour::*; - - - #[test] - fn git_blank() { - let mut details = Details::default(); - details.colours.punctuation = Fixed(44).normal(); - - let stati = f::Git { - staged: f::GitStatus::NotModified, - unstaged: f::GitStatus::NotModified, - }; - - let expected = TextCell { - width: DisplayWidth::from(2), - contents: vec![ - Fixed(44).paint("-"), - Fixed(44).paint("-"), - ].into(), - }; - - assert_eq!(expected, stati.render(&details.colours).into()) - } - - #[test] - fn git_new_changed() { - let mut details = Details::default(); - details.colours.git.new = Red.normal(); - details.colours.git.modified = Purple.normal(); - - let stati = f::Git { - staged: f::GitStatus::New, - unstaged: f::GitStatus::Modified, - }; - - let expected = TextCell { - width: DisplayWidth::from(2), - contents: vec![ - Red.paint("N"), - Purple.paint("M"), - ].into(), - }; - - assert_eq!(expected, stati.render(&details.colours).into()) - } - -} \ No newline at end of file