summaryrefslogtreecommitdiffstats
path: root/src/feature
diff options
context:
space:
mode:
authorBen S <ogham@bsago.me>2015-05-11 23:28:01 +0100
committerBen S <ogham@bsago.me>2015-05-11 23:28:01 +0100
commitdc6599b1b344370b851b9e9ca32ef62ba7d9a1c8 (patch)
tree47f1277d34621b1e93f38d4e487ed6ad92f9540e /src/feature
parentbc844a3843cdc56630cf87c8f3ba1f2d6aa4152f (diff)
Turn File into simply a data source
And move all the rendering, ansi_term, colourful stuff into the output modules, which is the only place they should be used!
Diffstat (limited to 'src/feature')
-rw-r--r--src/feature/git.rs56
1 files changed, 27 insertions, 29 deletions
diff --git a/src/feature/git.rs b/src/feature/git.rs
index db9cc0e..17ef7d8 100644
--- a/src/feature/git.rs
+++ b/src/feature/git.rs
@@ -1,9 +1,8 @@
use std::path::{Path, PathBuf};
-use ansi_term::{ANSIString, ANSIStrings};
use git2;
-use colours::Colours;
+use file;
/// Container of Git statuses for all the files in this folder's Git repository.
pub struct Git {
@@ -29,49 +28,48 @@ impl Git {
}
/// Get the status for the file at the given path, if present.
- pub fn status(&self, c: &Colours, path: &Path) -> String {
+ pub fn status(&self, path: &Path) -> file::Git {
let status = self.statuses.iter()
.find(|p| p.0.as_path() == path);
match status {
- Some(&(_, s)) => ANSIStrings( &[Git::index_status(c, s), Git::working_tree_status(c, s) ]).to_string(),
- None => c.punctuation.paint("--").to_string(),
+ Some(&(_, s)) => file::Git { staged: index_status(s), unstaged: working_tree_status(s) },
+ None => file::Git { staged: file::GitStatus::NotModified, unstaged: file::GitStatus::NotModified }
}
}
/// 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, c: &Colours, dir: &Path) -> String {
+ pub fn dir_status(&self, dir: &Path) -> file::Git {
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(c, s), Git::working_tree_status(c, s)] ).to_string()
+ file::Git { staged: index_status(s), unstaged: working_tree_status(s) }
}
+}
- /// The character to display if the file has been modified, but not staged.
- fn working_tree_status(colours: &Colours, status: git2::Status) -> ANSIString<'static> {
- match status {
- 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"),
- _ => colours.punctuation.paint("-"),
- }
+/// The character to display if the file has been modified, but not staged.
+fn working_tree_status(status: git2::Status) -> file::GitStatus {
+ match status {
+ s if s.contains(git2::STATUS_WT_NEW) => file::GitStatus::New,
+ s if s.contains(git2::STATUS_WT_MODIFIED) => file::GitStatus::Modified,
+ s if s.contains(git2::STATUS_WT_DELETED) => file::GitStatus::Deleted,
+ s if s.contains(git2::STATUS_WT_RENAMED) => file::GitStatus::Renamed,
+ s if s.contains(git2::STATUS_WT_TYPECHANGE) => file::GitStatus::TypeChange,
+ _ => file::GitStatus::NotModified,
}
+}
- /// The character to display if the file has been modified, and the change
- /// has been staged.
- fn index_status(colours: &Colours, status: git2::Status) -> ANSIString<'static> {
- match status {
- 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"),
- _ => colours.punctuation.paint("-"),
- }
+/// The character to display if the file has been modified, and the change
+/// has been staged.
+fn index_status(status: git2::Status) -> file::GitStatus {
+ match status {
+ s if s.contains(git2::STATUS_INDEX_NEW) => file::GitStatus::New,
+ s if s.contains(git2::STATUS_INDEX_MODIFIED) => file::GitStatus::Modified,
+ s if s.contains(git2::STATUS_INDEX_DELETED) => file::GitStatus::Deleted,
+ s if s.contains(git2::STATUS_INDEX_RENAMED) => file::GitStatus::Renamed,
+ s if s.contains(git2::STATUS_INDEX_TYPECHANGE) => file::GitStatus::TypeChange,
+ _ => file::GitStatus::NotModified,
}
}
-