[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:
Additional Information
No response
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()
))
})
}