2019-04-27 02:07:07 +00:00
|
|
|
use ansi_term::Color;
|
|
|
|
|
2019-05-01 20:34:24 +00:00
|
|
|
use super::{Context, Module};
|
2019-04-27 02:07:07 +00:00
|
|
|
|
|
|
|
/// Creates a segment with the Git branch in the current directory
|
|
|
|
///
|
|
|
|
/// Will display the branch name if the current directory is a git repo
|
2019-06-10 14:56:17 +00:00
|
|
|
pub fn segment<'a>(context: &'a Context) -> Option<Module<'a>> {
|
2019-05-14 04:43:11 +00:00
|
|
|
let branch_name = context.branch_name.as_ref()?;
|
2019-04-27 02:07:07 +00:00
|
|
|
|
2019-05-14 04:43:11 +00:00
|
|
|
const GIT_BRANCH_CHAR: &str = " ";
|
|
|
|
let segment_color = Color::Purple.bold();
|
2019-04-27 02:07:07 +00:00
|
|
|
|
2019-06-10 14:56:17 +00:00
|
|
|
let mut module = context.new_module("git_branch");
|
2019-05-14 04:43:11 +00:00
|
|
|
module.set_style(segment_color);
|
|
|
|
module.get_prefix().set_value("on ");
|
2019-04-27 02:07:07 +00:00
|
|
|
|
2019-05-14 04:43:11 +00:00
|
|
|
module.new_segment("branch_char", GIT_BRANCH_CHAR);
|
|
|
|
module.new_segment("branch_name", branch_name.to_string());
|
2019-04-27 02:07:07 +00:00
|
|
|
|
2019-05-14 04:43:11 +00:00
|
|
|
Some(module)
|
2019-04-27 02:07:07 +00:00
|
|
|
}
|