Move Git render_char to its own method

This commit is contained in:
Ben S 2015-05-12 03:36:47 +01:00
parent e2f2bd69de
commit c9a3affb4c

View File

@ -9,7 +9,7 @@ use users::{OSUsers, Users};
use super::filename; use super::filename;
use ansi_term::{ANSIStrings, Style}; use ansi_term::{ANSIString, ANSIStrings, Style};
use ansi_term::Style::Plain; use ansi_term::Style::Plain;
use locale; use locale;
@ -293,8 +293,15 @@ impl Table {
} }
fn render_git_status(&self, git: f::Git) -> Cell { fn render_git_status(&self, git: f::Git) -> Cell {
let render_char = |chr| { Cell {
match chr { text: ANSIStrings(&[ self.render_git_char(git.staged),
self.render_git_char(git.unstaged) ]).to_string(),
length: 2,
}
}
fn render_git_char(&self, status: f::GitStatus) -> ANSIString {
match status {
f::GitStatus::NotModified => self.colours.punctuation.paint("-"), f::GitStatus::NotModified => self.colours.punctuation.paint("-"),
f::GitStatus::New => self.colours.git.new.paint("N"), f::GitStatus::New => self.colours.git.new.paint("N"),
f::GitStatus::Modified => self.colours.git.modified.paint("M"), f::GitStatus::Modified => self.colours.git.modified.paint("M"),
@ -302,12 +309,6 @@ impl Table {
f::GitStatus::Renamed => self.colours.git.renamed.paint("R"), f::GitStatus::Renamed => self.colours.git.renamed.paint("R"),
f::GitStatus::TypeChange => self.colours.git.typechange.paint("T"), f::GitStatus::TypeChange => self.colours.git.typechange.paint("T"),
} }
};
Cell {
text: ANSIStrings(&[ render_char(git.staged), render_char(git.unstaged) ]).to_string(),
length: 2,
}
} }
fn render_user(&mut self, user: f::User) -> Cell { fn render_user(&mut self, user: f::User) -> Cell {