mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-11-24 21:57:41 +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:
parent
0a091bd236
commit
3513aae3ed
@ -28,6 +28,16 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||
},
|
||||
_ => 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)
|
||||
});
|
||||
|
||||
@ -237,4 +247,36 @@ mod tests {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user