Piturnah / gex

Git Explorer: cross-platform git workflow improvement tool inspired by Magit

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Feature]: Highlight conventional commits

Piturnah opened this issue · comments

Type of Feature

Style and UI

Description

Conventional commits is a commonly used specification to add structure to commit messages.

In gex we display the title of the most recent commit at the top of the status menu. I think it would be beneficial to highlight this semantic information similarly to how it's done in neovim:

image

Additional Information

No response

image

I've implemented it, but I think it looks pretty bad/distracting. If you see this, please let me know what you think.

Implementation:

/// Take a commit title and highlight it with respect to the conventional commit specifiction.
fn highlight_conventional_commit(s: &str) -> Cow<'_, str> {
    let commit_title: IResult<&str, (&str, Option<&str>)> = terminated(
        pair(
            take_while1(|c: char| c.is_alphanumeric()),
            opt(delimited(
                tag("("),
                take_while1(|c: char| c.is_alphanumeric()),
                tag(")"),
            )),
        ),
        tag(":"),
    )(s);
    commit_title.map_or(Cow::Borrowed(s), |(title, (topic, scope))| {
        Cow::Owned(format!(
            "{}{topic}{}{scope}:{title}",
            SetForegroundColor(Color::Red),
            SetForegroundColor(Color::Reset),
            scope = scope
                .map(|scope| format!(
                    "({}{scope}{})",
                    SetForegroundColor(Color::Blue),
                    SetForegroundColor(Color::Reset)
                ))
                .unwrap_or_default()
        ))
    })
}