diff --git a/.github/config-schema.json b/.github/config-schema.json index 2c01b2d34..2e1750e55 100644 --- a/.github/config-schema.json +++ b/.github/config-schema.json @@ -5983,6 +5983,18 @@ "default": "bold red", "type": "string" }, + "success_style": { + "type": [ + "string", + "null" + ] + }, + "failure_style": { + "type": [ + "string", + "null" + ] + }, "map_symbol": { "default": false, "type": "boolean" diff --git a/docs/config/README.md b/docs/config/README.md index 54321a84f..9f1574939 100644 --- a/docs/config/README.md +++ b/docs/config/README.md @@ -4281,6 +4281,8 @@ To enable it, set `disabled` to `false` in your configuration file. | `sigint_symbol` | `'🧱'` | The symbol displayed on SIGINT (Ctrl + c) | | `signal_symbol` | `'⚡'` | The symbol displayed on any signal | | `style` | `'bold red'` | The style for the module. | +| `success_style` | | The style used on program success (defaults to `style` if unset). | +| `failure_style` | | The style used on program failure (defaults to `style` if unset). | | `recognize_signal_code` | `true` | Enable signal mapping from exit code | | `map_symbol` | `false` | Enable symbols mapping from exit code | | `pipestatus` | `false` | Enable pipestatus reporting | @@ -4291,18 +4293,18 @@ To enable it, set `disabled` to `false` in your configuration file. ### Variables -| Variable | Example | Description | -| -------------- | ------- | ------------------------------------------------------------------------------------------ | -| status | `127` | The exit code of the last command | -| hex_status | `0x7F` | The exit code of the last command in hex | -| int | `127` | The exit code of the last command | -| common_meaning | `ERROR` | Meaning of the code if not a signal | -| signal_number | `9` | Signal number corresponding to the exit code, only if signalled | -| signal_name | `KILL` | Name of the signal corresponding to the exit code, only if signalled | -| maybe_int | `7` | Contains the exit code number when no meaning has been found | -| pipestatus | | Rendering of in pipeline programs' exit codes, this is only available in pipestatus_format | -| symbol | | Mirrors the value of option `symbol` | -| style\* | | Mirrors the value of option `style` | +| Variable | Example | Description | +| -------------- | ------- | -------------------------------------------------------------------------------------------- | +| status | `127` | The exit code of the last command | +| hex_status | `0x7F` | The exit code of the last command in hex | +| int | `127` | The exit code of the last command | +| common_meaning | `ERROR` | Meaning of the code if not a signal | +| signal_number | `9` | Signal number corresponding to the exit code, only if signalled | +| signal_name | `KILL` | Name of the signal corresponding to the exit code, only if signalled | +| maybe_int | `7` | Contains the exit code number when no meaning has been found | +| pipestatus | | Rendering of in pipeline programs' exit codes, this is only available in pipestatus_format | +| symbol | | Mirrors the value of option `symbol` | +| style\* | | Mirrors the value of option `success_style` on program success and `failure_style` otherwise | *: This variable can only be used as a part of a style string diff --git a/src/configs/status.rs b/src/configs/status.rs index a27f2ed23..1ff895cc1 100644 --- a/src/configs/status.rs +++ b/src/configs/status.rs @@ -16,6 +16,10 @@ pub struct StatusConfig<'a> { pub sigint_symbol: &'a str, pub signal_symbol: &'a str, pub style: &'a str, + #[serde(skip_serializing_if = "Option::is_none")] + pub success_style: Option<&'a str>, + #[serde(skip_serializing_if = "Option::is_none")] + pub failure_style: Option<&'a str>, pub map_symbol: bool, pub recognize_signal_code: bool, pub pipestatus: bool, @@ -37,6 +41,8 @@ impl<'a> Default for StatusConfig<'a> { sigint_symbol: "🧱", signal_symbol: "⚡", style: "bold red", + success_style: None, + failure_style: None, map_symbol: false, recognize_signal_code: true, pipestatus: false, diff --git a/src/modules/status.rs b/src/modules/status.rs index 6dfa168b1..d9276f2ec 100644 --- a/src/modules/status.rs +++ b/src/modules/status.rs @@ -158,7 +158,12 @@ fn format_exit_code<'a>( _ => None, }) .map_style(|variable| match variable { - "style" => Some(Ok(config.style)), + "style" => Some(Ok(if exit_code_int == 0 { + config.success_style + } else { + config.failure_style + } + .unwrap_or(config.style))), _ => None, }) .map(|variable| match variable {