|
|
@@ -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("-"),
|
|
|
}
|
|
|
}
|