A Git status character should render itself, too

This commit is contained in:
Benjamin Sago 2017-05-21 17:01:22 +01:00
parent 5f497da85d
commit f0cf5b4538

View File

@ -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 {