Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature]: Highlight conventional commits #32

Open
Piturnah opened this issue Jun 29, 2023 · 2 comments
Open

[Feature]: Highlight conventional commits #32

Piturnah opened this issue Jun 29, 2023 · 2 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@Piturnah
Copy link
Owner

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

@Piturnah Piturnah added enhancement New feature or request good first issue Good for newcomers labels Jun 29, 2023
@Piturnah
Copy link
Owner Author

image

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

@Piturnah
Copy link
Owner Author

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()
        ))
    })
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant