diff options
author | Artyom Belousov <flygrounder@yandex.ru> | 2022-07-19 16:07:50 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-19 15:07:50 +0200 |
commit | 61438484bdc76601a185298f14337cfb4d5b4e0b (patch) | |
tree | 39cc88bd2e14d0e13c2c06bc8236e0369af5ea90 /src | |
parent | 442d084962dde2a087a2afc1c3bd2878fe0c2789 (diff) |
feat(status): Add pipestatus_segment_format option to status module (#4103)
Add pipestatus_segment_format
Diffstat (limited to 'src')
-rw-r--r-- | src/configs/status.rs | 3 | ||||
-rw-r--r-- | src/modules/status.rs | 26 |
2 files changed, 28 insertions, 1 deletions
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); + } } |