diff options
author | Izhak Jakov <izak723@gmail.com> | 2022-03-16 16:05:13 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-16 16:05:13 -0400 |
commit | 86953272a7f1471e9a3422a7543d97b953406df6 (patch) | |
tree | e02d7647837a161e350e3c9aeb66191242994753 /src | |
parent | 52fa4bbab4393589aebbeded4351886e657a6275 (diff) |
fix(status): Make status module work even when the status is 0 (#3750)
Co-authored-by: Izhak Jakov <jizhak@ca.ibm.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/configs/status.rs | 2 | ||||
-rw-r--r-- | src/modules/status.rs | 56 |
2 files changed, 53 insertions, 5 deletions
diff --git a/src/configs/status.rs b/src/configs/status.rs index dda5f8191..9d6337eb7 100644 --- a/src/configs/status.rs +++ b/src/configs/status.rs @@ -26,7 +26,7 @@ impl<'a> Default for StatusConfig<'a> { StatusConfig { format: "[$symbol$status]($style) ", symbol: "✖", - success_symbol: "✔️", + success_symbol: "", not_executable_symbol: "🚫", not_found_symbol: "🔍", sigint_symbol: "🧱", diff --git a/src/modules/status.rs b/src/modules/status.rs index a3ae4fea9..43d21bfbb 100644 --- a/src/modules/status.rs +++ b/src/modules/status.rs @@ -17,7 +17,7 @@ enum PipeStatusStatus<'a> { /// Creates a module with the status of the last command /// -/// Will display the status only if it is not 0 +/// Will display the status pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> { let mut module = context.new_module("status"); let config = StatusConfig::try_load(module.config); @@ -43,8 +43,9 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> { false => PipeStatusStatus::Disabled, }; - // Exit code is zero and pipestatus is all zero or disabled/missing + // Exit code is zero while success_symbol and pipestatus are all zero or disabled/missing if exit_code == "0" + && config.success_symbol.is_empty() && (match pipestatus_status { PipeStatusStatus::Pipe(ps) => ps.iter().all(|s| s == "0"), _ => true, @@ -176,7 +177,7 @@ fn status_common_meaning(ex: ExitCode) -> Option<&'static str> { return None; } match ex { - 0 => Some(""), + 0 => Some(""), // SUCCESS can be defined by $success_symbol if the user wishes too. 1 => Some("ERROR"), 2 => Some("USAGE"), 126 => Some("NOPERM"), @@ -228,13 +229,59 @@ mod tests { use crate::test::ModuleRenderer; #[test] - fn success_status() { + fn success_status_success_symbol_empty() { let expected = None; + // Status code 0 and success_symbol = "" + let actual = ModuleRenderer::new("status") + .config(toml::toml! { + [status] + success_symbol = "" + disabled = false + }) + .status(0) + .collect(); + assert_eq!(expected, actual); + + // Status code 0 and success_symbol is missing + let actual = ModuleRenderer::new("status") + .config(toml::toml! { + [status] + disabled = false + }) + .status(0) + .collect(); + assert_eq!(expected, actual); + + // No status code and success_symbol = "" + let actual = ModuleRenderer::new("status") + .config(toml::toml! { + [status] + success_symbol = "" + disabled = false + }) + .collect(); + assert_eq!(expected, actual); + + // No status code and success_symbol is missing + let actual = ModuleRenderer::new("status") + .config(toml::toml! { + [status] + disabled = false + }) + .collect(); + assert_eq!(expected, actual); + } + + #[test] + fn success_status_success_symbol_filled() { + let expected = Some(format!("{} ", Color::Red.bold().paint("✔️0"))); + // Status code 0 let actual = ModuleRenderer::new("status") .config(toml::toml! { [status] + success_symbol = "✔️" disabled = false }) .status(0) @@ -245,6 +292,7 @@ mod tests { let actual = ModuleRenderer::new("status") .config(toml::toml! { [status] + success_symbol = "✔️" disabled = false }) .collect(); |