error indicator
This commit is contained in:
parent
24f3f6772e
commit
7257faf85d
17
src/indicators/error.rs
Normal file
17
src/indicators/error.rs
Normal file
@ -0,0 +1,17 @@
|
||||
use ansi_term::ANSIGenericString;
|
||||
use ansi_term::Colour::RGB;
|
||||
|
||||
// Error indicator symbol
|
||||
pub const ERR_SYMBOL: &str = "\u{276F}"; // "❯"
|
||||
pub const ERR_COL: ansi_term::Colour = RGB(255, 53, 94); //
|
||||
pub const NORMIE_COL: ansi_term::Colour = RGB(0, 255, 180); //
|
||||
|
||||
// Error indicator
|
||||
pub fn indicator(args: Vec<String>) -> ANSIGenericString<'static, str> {
|
||||
let default_exit_code = "0".to_string();
|
||||
let exit_code = args.get(1).unwrap_or(&default_exit_code); // Default to "0" if missing
|
||||
match exit_code.as_str() {
|
||||
"0" => NORMIE_COL.paint(ERR_SYMBOL),
|
||||
_ => ERR_COL.paint(ERR_SYMBOL),
|
||||
}
|
||||
}
|
16
src/main.rs
16
src/main.rs
@ -1,20 +1,26 @@
|
||||
mod indicators {
|
||||
pub mod error;
|
||||
pub mod git;
|
||||
pub mod ssh;
|
||||
pub mod user;
|
||||
}
|
||||
use indicators::git;
|
||||
|
||||
use crate::indicators::error;
|
||||
use crate::indicators::git;
|
||||
use crate::indicators::ssh;
|
||||
use crate::indicators::user;
|
||||
|
||||
fn main() {
|
||||
let cmd_args: Vec<String> = std::env::args().collect();
|
||||
let mut prompt: String = String::new();
|
||||
|
||||
let indicate_user: bool = true;
|
||||
let indicate_ssh: bool = true;
|
||||
let indicate_err: bool = true;
|
||||
let indicate_git_branch: bool = true;
|
||||
|
||||
if indicate_ssh {
|
||||
prompt += &ssh::indicator().to_string();
|
||||
}
|
||||
if indicate_git_branch {
|
||||
let git_info = git::info();
|
||||
match git_info {
|
||||
@ -22,11 +28,11 @@ fn main() {
|
||||
None => prompt += &git::indicator(None).to_string(),
|
||||
};
|
||||
}
|
||||
if indicate_ssh {
|
||||
prompt += &ssh::indicator().to_string();
|
||||
}
|
||||
if indicate_user {
|
||||
prompt += &user::indicator().to_string();
|
||||
}
|
||||
if indicate_err {
|
||||
prompt += &error::indicator(cmd_args).to_string();
|
||||
}
|
||||
print!("{prompt} ");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user