From 7257faf85d0eee94560fcf9e4eb08494fad85a2f Mon Sep 17 00:00:00 2001 From: candifloss Date: Mon, 25 Nov 2024 13:23:37 +0530 Subject: [PATCH] error indicator --- src/indicators/error.rs | 17 +++++++++++++++++ src/main.rs | 16 +++++++++++----- 2 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 src/indicators/error.rs diff --git a/src/indicators/error.rs b/src/indicators/error.rs new file mode 100644 index 0000000..56a5a7c --- /dev/null +++ b/src/indicators/error.rs @@ -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) -> 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), + } +} diff --git a/src/main.rs b/src/main.rs index c4d3caf..4039fd9 100644 --- a/src/main.rs +++ b/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 = 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} "); }