mirror of
https://github.com/Llewellynvdm/starship.git
synced 2025-02-14 17:56:30 +00: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 {
|
self.iter().fold(BTreeSet::new(), |mut acc, el| match el {
|
||||||
FormatElement::TextGroup(textgroup) => {
|
FormatElement::TextGroup(textgroup) => {
|
||||||
acc.extend(textgroup.style.get_style_variables());
|
acc.extend(textgroup.style.get_style_variables());
|
||||||
|
acc.extend(textgroup.format.get_style_variables());
|
||||||
acc
|
acc
|
||||||
}
|
}
|
||||||
FormatElement::Conditional(format) => {
|
FormatElement::Conditional(format) => {
|
||||||
|
@ -569,6 +569,30 @@ mod tests {
|
|||||||
match_next!(result_iter, "inner", inner_style);
|
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]
|
#[test]
|
||||||
fn test_styled_variable_as_text() {
|
fn test_styled_variable_as_text() {
|
||||||
const FORMAT_STR: &str = "[$var](red bold)";
|
const FORMAT_STR: &str = "[$var](red bold)";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user