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
|
|
|
|
2019-07-19 20:18:52 +00:00
|
|
|
/// Creates a module with the Git branch in the current directory
|
2019-04-27 02:07:07 +00:00
|
|
|
///
|
|
|
|
/// Will display the branch name if the current directory is a git repo
|
2019-07-02 20:12:53 +00:00
|
|
|
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
2019-05-14 04:43:11 +00:00
|
|
|
const GIT_BRANCH_CHAR: &str = " ";
|
2019-07-31 23:48:51 +00:00
|
|
|
|
|
|
|
let branch_name = context.branch_name.as_ref()?;
|
2019-05-14 04:43:11 +00:00
|
|
|
let segment_color = Color::Purple.bold();
|
2019-04-27 02:07:07 +00:00
|
|
|
|
2019-07-02 20:12:53 +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-07-19 20:18:52 +00:00
|
|
|
module.new_segment("symbol", GIT_BRANCH_CHAR);
|
|
|
|
module.new_segment("name", branch_name);
|
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
|
|
|
}
|