1
0
mirror of https://github.com/Llewellynvdm/starship.git synced 2024-11-28 15:56:28 +00:00

fix(shell): Support conditional format strings for $indicator (#2489)

Previously attempting to use conditional format strings with
`$indicator` would never display an indicator, e.g.:

```toml
[shell]
fish_indicator = ""
bash_indicator = "B "
format = "($indicator )"
disabled = false
```

This would always display an empty string.

Fixes #2474.
This commit is contained in:
Andy Freeland 2021-03-23 14:20:29 -07:00 committed by GitHub
parent 0a091bd236
commit 3513aae3ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -28,6 +28,16 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
}, },
_ => None, _ => None,
}) })
.map(|var| match var {
"bash_indicator" => Some(Ok(config.bash_indicator)),
"fish_indicator" => Some(Ok(config.fish_indicator)),
"zsh_indicator" => Some(Ok(config.zsh_indicator)),
"powershell_indicator" => Some(Ok(config.powershell_indicator)),
"ion_indicator" => Some(Ok(config.ion_indicator)),
"elvish_indicator" => Some(Ok(config.elvish_indicator)),
"tcsh_indicator" => Some(Ok(config.tcsh_indicator)),
_ => None,
})
.parse(None) .parse(None)
}); });
@ -237,4 +247,36 @@ mod tests {
assert_eq!(expected, actual); assert_eq!(expected, actual);
} }
#[test]
fn test_custom_format_conditional_indicator_match() {
let expected = Some(format!("{} ", "B"));
let actual = ModuleRenderer::new("shell")
.shell(Shell::Bash)
.config(toml::toml! {
[shell]
bash_indicator = "B"
format = "($bash_indicator )"
disabled = false
})
.collect();
assert_eq!(expected, actual);
}
#[test]
fn test_custom_format_conditional_indicator_no_match() {
let expected = None;
let actual = ModuleRenderer::new("shell")
.shell(Shell::Fish)
.config(toml::toml! {
[shell]
bash_indicator = "B"
format = "($indicator )"
disabled = false
})
.collect();
assert_eq!(expected, actual);
}
} }