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

Commit summary length hints (warning at 50, error at 72) #1954

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed
* do not allow tag when `tag.gpgsign` enabled [[@TeFiLeDo](https://github.com/TeFiLeDo)] ([#1915](https://github.com/extrawurst/gitui/pull/1915))
* update commit summary length hints [[@ochirerkhembayar](https://github.com/OchirErkhembayar)] ([#1635](https://github.com/extrawurst/gitui/issues/1635))

## [0.24.3] - 2023-09-09

Expand Down
15 changes: 11 additions & 4 deletions src/components/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ pub struct CommitComponent {
verify: bool,
}

const FIRST_LINE_LIMIT: usize = 50;
const MESSAGE_WARNING_LIMIT: usize = 50;
const MESSAGE_ERROR_LIMIT: usize = 72;

impl CommitComponent {
///
Expand Down Expand Up @@ -123,11 +124,17 @@ impl CommitComponent {
.map(str::len)
.unwrap_or_default();

if first_line > FIRST_LINE_LIMIT {
if first_line > MESSAGE_WARNING_LIMIT {
let msg = strings::commit_first_line_warning(first_line);
let msg_length: u16 = msg.len().cast();
let w =
Paragraph::new(msg).style(self.theme.text_danger());
let w = {
let theme = if first_line > MESSAGE_ERROR_LIMIT {
self.theme.text_danger()
} else {
self.theme.text_warning()
};
Paragraph::new(msg).style(theme)
};

let rect = {
let mut rect = self.input.get_area();
Expand Down
6 changes: 6 additions & 0 deletions src/ui/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub struct Theme {
commit_time: Color,
commit_author: Color,
danger_fg: Color,
warning_fg: Color,
push_gauge_bg: Color,
push_gauge_fg: Color,
tag_fg: Color,
Expand Down Expand Up @@ -193,6 +194,10 @@ impl Theme {
Style::default().fg(self.danger_fg)
}

pub fn text_warning(&self) -> Style {
Style::default().fg(self.warning_fg)
}

pub fn line_break(&self) -> String {
self.line_break.clone()
}
Expand Down Expand Up @@ -337,6 +342,7 @@ impl Default for Theme {
commit_time: Color::LightCyan,
commit_author: Color::Green,
danger_fg: Color::Red,
warning_fg: Color::Yellow,
push_gauge_bg: Color::Blue,
push_gauge_fg: Color::Reset,
tag_fg: Color::LightMagenta,
Expand Down