diff options
author | Ben S <ogham@bsago.me> | 2015-05-10 17:57:21 +0100 |
---|---|---|
committer | Ben S <ogham@bsago.me> | 2015-05-10 17:57:21 +0100 |
commit | d9319c48b427881a197d96a15b941534646f42ac (patch) | |
tree | 0f6a5bfd26a7fb2a8b017ba542026bbc68cc14bb /src/feature | |
parent | 5a37d1b6b16e72c0661d3a465ab1c56f458384d8 (diff) |
Do the same for the Git column
Diffstat (limited to 'src/feature')
-rw-r--r-- | src/feature/git.rs | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/src/feature/git.rs b/src/feature/git.rs index 0d1fb23..03e6a5d 100644 --- a/src/feature/git.rs +++ b/src/feature/git.rs @@ -1,9 +1,9 @@ use std::path::{Path, PathBuf}; use ansi_term::{ANSIString, ANSIStrings}; -use ansi_term::Colour::*; use git2; +use colours::Colours; use file::GREY; /// Container of Git statuses for all the files in this folder's Git repository. @@ -30,11 +30,11 @@ impl Git { } /// Get the status for the file at the given path, if present. - pub fn status(&self, path: &Path) -> String { + pub fn status(&self, c: &Colours, path: &Path) -> String { let status = self.statuses.iter() .find(|p| p.0.as_path() == path); match status { - Some(&(_, s)) => ANSIStrings( &[Git::index_status(s), Git::working_tree_status(s) ]).to_string(), + Some(&(_, s)) => ANSIStrings( &[Git::index_status(c, s), Git::working_tree_status(c, s) ]).to_string(), None => GREY.paint("--").to_string(), } } @@ -42,35 +42,35 @@ impl Git { /// Get the combined status for all the files whose paths begin with the /// path that gets passed in. This is used for getting the status of /// directories, which don't really have an 'official' status. - pub fn dir_status(&self, dir: &Path) -> String { + pub fn dir_status(&self, c: &Colours, dir: &Path) -> String { let s = self.statuses.iter() .filter(|p| p.0.starts_with(dir)) .fold(git2::Status::empty(), |a, b| a | b.1); - ANSIStrings( &[Git::index_status(s), Git::working_tree_status(s)] ).to_string() + ANSIStrings( &[Git::index_status(c, s), Git::working_tree_status(c, s)] ).to_string() } /// The character to display if the file has been modified, but not staged. - fn working_tree_status(status: git2::Status) -> ANSIString<'static> { + fn working_tree_status(colours: &Colours, status: git2::Status) -> ANSIString<'static> { match status { - s if s.contains(git2::STATUS_WT_NEW) => Green.paint("A"), - s if s.contains(git2::STATUS_WT_MODIFIED) => Blue.paint("M"), - s if s.contains(git2::STATUS_WT_DELETED) => Red.paint("D"), - s if s.contains(git2::STATUS_WT_RENAMED) => Yellow.paint("R"), - s if s.contains(git2::STATUS_WT_TYPECHANGE) => Purple.paint("T"), + s if s.contains(git2::STATUS_WT_NEW) => colours.git.new.paint("A"), + s if s.contains(git2::STATUS_WT_MODIFIED) => colours.git.modified.paint("M"), + s if s.contains(git2::STATUS_WT_DELETED) => colours.git.deleted.paint("D"), + s if s.contains(git2::STATUS_WT_RENAMED) => colours.git.renamed.paint("R"), + s if s.contains(git2::STATUS_WT_TYPECHANGE) => colours.git.typechange.paint("T"), _ => GREY.paint("-"), } } /// The character to display if the file has been modified, and the change /// has been staged. - fn index_status(status: git2::Status) -> ANSIString<'static> { + fn index_status(colours: &Colours, status: git2::Status) -> ANSIString<'static> { match status { - s if s.contains(git2::STATUS_INDEX_NEW) => Green.paint("A"), - s if s.contains(git2::STATUS_INDEX_MODIFIED) => Blue.paint("M"), - s if s.contains(git2::STATUS_INDEX_DELETED) => Red.paint("D"), - s if s.contains(git2::STATUS_INDEX_RENAMED) => Yellow.paint("R"), - s if s.contains(git2::STATUS_INDEX_TYPECHANGE) => Purple.paint("T"), + s if s.contains(git2::STATUS_INDEX_NEW) => colours.git.new.paint("A"), + s if s.contains(git2::STATUS_INDEX_MODIFIED) => colours.git.modified.paint("M"), + s if s.contains(git2::STATUS_INDEX_DELETED) => colours.git.deleted.paint("D"), + s if s.contains(git2::STATUS_INDEX_RENAMED) => colours.git.renamed.paint("R"), + s if s.contains(git2::STATUS_INDEX_TYPECHANGE) => colours.git.typechange.paint("T"), _ => GREY.paint("-"), } } |