mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-12-25 11:20:01 +00:00
feat(status): Add pipestatus_segment_format option to status module (#4103)
Add pipestatus_segment_format
This commit is contained in:
parent
442d084962
commit
61438484bd
6
.github/config-schema.json
vendored
6
.github/config-schema.json
vendored
@ -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"
|
||||
|
@ -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
|
||||
|
||||
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user