From 94559380d3d487071005e35d2a0e8e40447e267e Mon Sep 17 00:00:00 2001 From: candifloss Date: Sun, 18 Aug 2024 08:35:00 +0530 Subject: [PATCH] root indicator and err indicator --- src/main.rs | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 628672c..8d98fef 100644 --- a/src/main.rs +++ b/src/main.rs @@ -102,22 +102,33 @@ fn main() -> std::io::Result<()> { let angle = "❯"; //Root user indicator - let _user = var_os("USER").expect("UnknownUser").to_str().expect("UnknownUser").to_string(); - /* - if user == "root" { - println!("root_user"); - }*/ + let user = var_os("USER").expect("UnknownUser").to_str().expect("UnknownUser").to_string(); + + let mut err = ""; //Shell symbol let args: Vec = args().collect(); let shell: String; if args.len() > 1 { shell = args[1].clone(); + if args.len() > 2 { + err = args[2].as_str(); + } } else { shell = "none".to_string(); } + let root_indicator = match user.as_str() { + "root" => angle.truecolor(255, 53, 94), + _ => angle.truecolor(0, 255, 180), + }; + + let err_indicator = match err { + "0" => angle.truecolor(0, 255, 180), + _ => angle.truecolor(255, 53, 94), + }; + //SSH shell indicator let ssh_char:ColoredString; match var_os("SSH_TTY") { @@ -125,7 +136,7 @@ fn main() -> std::io::Result<()> { ssh_char = " ".truecolor(0,150,180); }, None => { - ssh_char = "".truecolor(34,109,155); + ssh_char = "".clear(); } } @@ -143,14 +154,16 @@ fn main() -> std::io::Result<()> { cur_dir = cur_dir.replace(&homedir, "~"); // Abreviate homedir with "~" cur_dir = abrev_path(cur_dir); - print!("{}{}{}{}{}{} ", + print!("{}{}{}{}{}{}{} ", ssh_char, get_shell_char(shell).truecolor(75,75,75), git_repo_name, git_char, //abrev_path(pwd,homedir).italic().truecolor(82,82,82), cur_dir.italic().truecolor(82,82,82), - angle.truecolor(0, 255, 180), + //angle.truecolor(0, 255, 180), + root_indicator, + err_indicator, ); Ok(())