From f0cf5b4538847e2911856d0f1996fa0e09bc21f8 Mon Sep 17 00:00:00 2001 From: Benjamin Sago Date: Sun, 21 May 2017 17:01:22 +0100 Subject: [PATCH] A Git status character should render itself, too --- src/output/render/git.rs | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/output/render/git.rs b/src/output/render/git.rs index 20080bd..ee8f31b 100644 --- a/src/output/render/git.rs +++ b/src/output/render/git.rs @@ -1,3 +1,5 @@ +use ansi_term::ANSIString; + use output::cell::{TextCell, DisplayWidth}; use output::colours::Colours; use fs::fields as f; @@ -5,25 +7,29 @@ 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) + self.staged.render(colours), + self.unstaged.render(colours), ].into(), } } } +impl f::GitStatus { + fn render(&self, colours: &Colours) -> ANSIString<'static> { + match *self { + 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"), + } + } +} + #[cfg(test)] pub mod test {