diff --git a/src/main.rs b/src/main.rs index 2a8630d..61cffe5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,11 +11,12 @@ use crate::indicators::git; use crate::indicators::pwd; use crate::indicators::ssh; use crate::indicators::user; +use ansi_term::{ANSIGenericString, ANSIGenericStrings}; fn main() { - let cmd_args: Vec = std::env::args().collect(); + let cmd_args: Vec = std::env::args().collect(); // Cmd-line args - let mut components: Vec = Vec::new(); + let mut components: Vec> = Vec::new(); // The components will be concated into one string let indicate_user: bool = true; let indicate_ssh: bool = true; @@ -25,23 +26,27 @@ fn main() { let abbrev_home: bool = true; let shorten_path: bool = true; let replace_repo: bool = true; - let mut git_info = None; + + let git_info: Option<(String, String)> = if indicate_git_branch || replace_repo { + git::info() + } else { + None + }; if indicate_ssh { - components.push(ssh::indicator().to_string()); + components.push(ssh::indicator()); } if indicate_git_branch { - git_info = git::info(); match git_info { - Some(ref info) => components.push(git::indicator(Some(info.1.clone())).to_string()), - None => components.push(git::indicator(None).to_string()), + Some(ref info) => components.push(git::indicator(Some(info.1.clone()))), + None => components.push(git::indicator(None)), } } if indicate_user { - components.push(user::indicator().to_string()); + components.push(user::indicator()); } if indicate_err { - components.push(error::indicator(cmd_args).to_string()); + components.push(error::indicator(cmd_args)); } if show_pwd { let repo_path = match git_info { @@ -50,9 +55,9 @@ fn main() { }; components.insert( 0, - pwd::pwd(abbrev_home, shorten_path, replace_repo, repo_path).to_string(), + pwd::pwd(abbrev_home, shorten_path, replace_repo, repo_path), ); } - let prompt = components.join(""); + let prompt: ANSIGenericStrings<'_, str> = ANSIGenericStrings(&components[..]); print!("{prompt} "); }