diff options
-rw-r--r-- | .github/config-schema.json | 6 | ||||
-rw-r--r-- | docs/config/README.md | 33 | ||||
-rw-r--r-- | src/configs/status.rs | 3 | ||||
-rw-r--r-- | src/modules/status.rs | 26 |
4 files changed, 51 insertions, 17 deletions
diff --git a/.github/config-schema.json b/.github/config-schema.json index 99d164f76..351dd9856 100644 --- a/.github/config-schema.json +++ b/.github/config-schema.json @@ -4521,6 +4521,12 @@ "default": "\\[$pipestatus\\] => [$symbol$common_meaning$signal_name$maybe_int]($style)", "type": "string" }, + "pipestatus_segment_format": { + "type": [ + "string", + "null" + ] + }, "disabled": { "default": true, "type": "boolean" diff --git a/docs/config/README.md b/docs/config/README.md index 7316b86dd..cba894e71 100644 --- a/docs/config/README.md +++ b/docs/config/README.md @@ -3322,22 +3322,23 @@ To enable it, set `disabled` to `false` in your configuration file. ### Options -| Option | Default | Description | -| ----------------------- | ----------------------------------------------------------------------------- | ------------------------------------------------------- | -| `format` | `"[$symbol$status]($style) "` | The format of the module | -| `symbol` | `"✖"` | The symbol displayed on program error | -| `success_symbol` | `""` | The symbol displayed on program success | -| `not_executable_symbol` | `"🚫"` | The symbol displayed when file isn't executable | -| `not_found_symbol` | `"🔍"` | The symbol displayed when the command can't be found | -| `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. | -| `recognize_signal_code` | `true` | Enable signal mapping from exit code | -| `map_symbol` | `false` | Enable symbols mapping from exit code | -| `pipestatus` | `false` | Enable pipestatus reporting | -| `pipestatus_separator` | ` | ` | -| `pipestatus_format` | `\\[$pipestatus\\] => [$symbol$common_meaning$signal_name$maybe_int]($style)` | The format of the module when the command is a pipeline | -| `disabled` | `true` | Disables the `status` module. | +| Option | Default | Description | +| --------------------------- | ----------------------------------------------------------------------------- | --------------------------------------------------------------------- | +| `format` | `"[$symbol$status]($style) "` | The format of the module | +| `symbol` | `"✖"` | The symbol displayed on program error | +| `success_symbol` | `""` | The symbol displayed on program success | +| `not_executable_symbol` | `"🚫"` | The symbol displayed when file isn't executable | +| `not_found_symbol` | `"🔍"` | The symbol displayed when the command can't be found | +| `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. | +| `recognize_signal_code` | `true` | Enable signal mapping from exit code | +| `map_symbol` | `false` | Enable symbols mapping from exit code | +| `pipestatus` | `false` | Enable pipestatus reporting | +| `pipestatus_separator` | <code>|</code> | The symbol used to separate pipestatus segments | +| `pipestatus_format` | `\\[$pipestatus\\] => [$symbol$common_meaning$signal_name$maybe_int]($style)` | The format of the module when the command is a pipeline | +| `pipestatus_segment_format` | | When specified, replaces `format` when formatting pipestatus segments | +| `disabled` | `true` | Disables the `status` module. | ### Variables diff --git a/src/configs/status.rs b/src/configs/status.rs index 422369b6f..839c57e67 100644 --- a/src/configs/status.rs +++ b/src/configs/status.rs @@ -17,6 +17,8 @@ pub struct StatusConfig<'a> { pub pipestatus: bool, pub pipestatus_separator: &'a str, pub pipestatus_format: &'a str, + #[serde(skip_serializing_if = "Option::is_none")] + pub pipestatus_segment_format: Option<&'a str>, pub disabled: bool, } @@ -37,6 +39,7 @@ impl<'a> Default for StatusConfig<'a> { pipestatus_separator: "|", pipestatus_format: "\\[$pipestatus\\] => [$symbol$common_meaning$signal_name$maybe_int]($style)", + pipestatus_segment_format: None, disabled: true, } } diff --git a/src/modules/status.rs b/src/modules/status.rs index e1c7e8cb7..444b5a30e 100644 --- a/src/modules/status.rs +++ b/src/modules/status.rs @@ -54,12 +54,14 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> { return None; } + let segment_format = config.pipestatus_segment_format.unwrap_or(config.format); + // Create pipestatus string let pipestatus = match pipestatus_status { PipeStatusStatus::Pipe(pipestatus) => pipestatus .iter() .map( - |ec| match format_exit_code(ec.as_str(), config.format, None, &config, context) { + |ec| match format_exit_code(ec.as_str(), segment_format, None, &config, context) { Ok(segments) => segments .into_iter() .map(|s| s.to_string()) @@ -684,4 +686,26 @@ mod tests { assert_eq!(expected, actual); } } + + #[test] + fn pipestatus_segment_format() { + let pipe_exit_code = &[0, 1]; + let main_exit_code = 1; + + let expected = Some("[0]|[1] => <1>".to_string()); + let actual = ModuleRenderer::new("status") + .config(toml::toml! { + [status] + format = "\\($status\\)" + pipestatus = true + pipestatus_separator = "|" + pipestatus_format = "$pipestatus => <$status>" + pipestatus_segment_format = "\\[$status\\]" + disabled = false + }) + .status(main_exit_code) + .pipestatus(pipe_exit_code) + .collect(); + assert_eq!(expected, actual); + } } |