mirror of
https://github.com/starship/starship.git
synced 2024-11-22 08:14:10 +01:00
fix(style): ensure nested style variables are processed during formatting (#5120)
fix: ensure nested style variables are processed during formatting
This commit is contained in:
parent
43651af4b9
commit
e5cec9ea50
@ -91,6 +91,7 @@ impl<'a> StyleVariableHolder<Cow<'a, str>> for Vec<FormatElement<'a>> {
|
||||
self.iter().fold(BTreeSet::new(), |mut acc, el| match el {
|
||||
FormatElement::TextGroup(textgroup) => {
|
||||
acc.extend(textgroup.style.get_style_variables());
|
||||
acc.extend(textgroup.format.get_style_variables());
|
||||
acc
|
||||
}
|
||||
FormatElement::Conditional(format) => {
|
||||
|
@ -569,6 +569,30 @@ mod tests {
|
||||
match_next!(result_iter, "inner", inner_style);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_style_variable_nested() {
|
||||
const STYLE_VAR_NAME: &str = "style";
|
||||
|
||||
let format_string = format!("[[text](${STYLE_VAR_NAME})](blue)");
|
||||
let inner_style = Some(Color::Red.bold());
|
||||
|
||||
let formatter = StringFormatter::new(&format_string)
|
||||
.unwrap()
|
||||
.map_style(|variable| match variable {
|
||||
STYLE_VAR_NAME => Some(Ok("red bold".to_owned())),
|
||||
_ => None,
|
||||
});
|
||||
|
||||
assert_eq!(
|
||||
BTreeSet::from([STYLE_VAR_NAME.into()]),
|
||||
formatter.get_style_variables()
|
||||
);
|
||||
|
||||
let result = formatter.parse(None, None).unwrap();
|
||||
let mut result_iter = result.iter();
|
||||
match_next!(result_iter, "text", inner_style);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_styled_variable_as_text() {
|
||||
const FORMAT_STR: &str = "[$var](red bold)";
|
||||
|
Loading…
Reference in New Issue
Block a user