Repository: starship/starship
File: src/formatter/string_formatter.rs (Rust)

Code before:
                            None => Ok("".into()),
                        }
                    }
                })
                .collect::<Result<Vec<Cow<str>>, StringFormatterError>>();
            style_strings
                .map(|style_strings| {
                    let style_string: String =
                        style_strings.iter().flat_map(|s| s.chars()).collect();
                    parse_style_string(&style_string, context)
                })
                .transpose()
        }

        fn parse_format<'a>(
            format: Vec<FormatElement<'a>>,
            style: Option<Style>,
            variables: &'a VariableMapType<'a>,
            style_variables: &'a StyleVariableMapType<'a>,
            context: Option<&Context>,
        ) -> Result<Vec<Segment>, StringFormatterError> {
            // Empty textgroups still produce a segment to preserve style for prev_fg/prev_bg references
            if format.is_empty() {
                return Ok(Segment::from_text(style, ""));
            }

            let results: Result<Vec<Vec<Segment>>, StringFormatterError> = format
                .into_iter()
                .map(|el| {
                    match el {
                        FormatElement::Text(text) => Ok(Segment::from_text(
                            style,
                            shell_prompt_escape(
                                text,
                                match context {
                                    None => Shell::Unknown,
                                    Some(c) => c.shell,
                                },
                            ),
                        )),
                        FormatElement::TextGroup(textgroup) => {
                            parse_textgroup(textgroup, variables, style_variables, context)
                        }
                        FormatElement::Variable(name) => variables
                            .get(name.as_ref())
                            .expect("Uncached variable found")
                            .as_ref()
                            .map(|segments| match segments.clone()? {
                                VariableValue::Styled(segments) => Ok(segments
                                    .into_iter()
                                    .map(|mut segment| {

Review comment (refactor):
Please move this into `parse_textgroup`:
```rust
let style = parse_style(textgroup.style, style_variables, context).transpose()?;

// Empty textgroups still produce a segment to preserve style for prev_fg/prev_bg references
if textgroup.format.is_empty() {
    return Ok(Segment::from_text(style, ""));
}
parse_format(
    textgroup.format,
    style,
    variables,
    style_variables,
    context,
)
```` 
               

Code after:
                        }
                    }
                })
                .collect::<Result<Vec<Cow<str>>, StringFormatterError>>();
            style_strings
                .map(|style_strings| {
                    let style_string: String =
                        style_strings.iter().flat_map(|s| s.chars()).collect();
                    parse_style_string(&style_string, context)
                })
                .transpose()
        }

        fn parse_format<'a>(
            format: Vec<FormatElement<'a>>,
            style: Option<Style>,
            variables: &'a VariableMapType<'a>,
            style_variables: &'a StyleVariableMapType<'a>,
            context: Option<&Context>,
        ) -> Result<Vec<Segment>, StringFormatterError> {
            let results: Result<Vec<Vec<Segment>>, StringFormatterError> = format
                .into_iter()
                .map(|el| {
                    match el {
                        FormatElement::Text(text) => Ok(Segment::from_text(
                            style,
                            shell_prompt_escape(
                                text,
                                match context {
                                    None => Shell::Unknown,
                                    Some(c) => c.shell,
                                },
                            ),
                        )),
                        FormatElement::TextGroup(textgroup) => {
                            parse_textgroup(textgroup, variables, style_variables, context)
                        }
                        FormatElement::Variable(name) => variables
                            .get(name.as_ref())
                            .expect("Uncached variable found")
                            .as_ref()
                            .map(|segments| match segments.clone()? {
                                VariableValue::Styled(segments) => Ok(segments
                                    .into_iter()
                                    .map(|mut segment| {
                                        // Derive upper style if the style of segments are none.
                                        segment.set_style_if_empty(style);
                                        segment
                                    })
                                    .collect()),
                                VariableValue::Plain(text) => Ok(Segment::from_text(