brain: Keep pending progress below completion
95942f2df99f2e17b5758af3684e36eecf4edadf
A history row with one hunk left could show a green 100% value even though the commit was still pending. Round the displayed percentage down and derive its color only from the review state, so completion text and the state marker stay consistent. Assisted-by: Codex:gpt-5.6-sol
1 parent
5f0bf32d
crates/brain/src/session/status.rs
+31 -14
| 458 | 458 | let identity_style = if matches!(slot.state, CommitReviewState::Dropped) { |
|
| 459 | 459 | Style::default().dim().strikethrough() |
|
| 460 | 460 | } else { |
|
| 461 | 461 | Style::default() |
|
| 462 | 462 | }; |
|
| 463 | - | let percent = slot.progress.filled(100); |
|
| 464 | - | let hunk_color = match (slot.state, percent) { |
|
| 465 | - | (CommitReviewState::Rejected, _) => palette.negative_fg, |
|
| 466 | - | (_, 0) => colors::fixed::MUTED, |
|
| 467 | - | (_, 100) => palette.positive_fg, |
|
| 468 | - | _ => Color::White, |
|
| 463 | + | let percent = if slot.progress.total == 0 { |
|
| 464 | + | 0 |
|
| 465 | + | } else { |
|
| 466 | + | slot.progress |
|
| 467 | + | .accepted |
|
| 468 | + | .saturating_mul(100) |
|
| 469 | + | .div_euclid(slot.progress.total) |
|
| 470 | + | .min(100) |
|
| 471 | + | }; |
|
| 472 | + | let hunk_color = match slot.state { |
|
| 473 | + | CommitReviewState::Rejected => palette.negative_fg, |
|
| 474 | + | CommitReviewState::Accepted => palette.positive_fg, |
|
| 475 | + | CommitReviewState::Pending => Color::White, |
|
| 476 | + | CommitReviewState::Dropped => colors::fixed::MUTED, |
|
| 469 | 477 | }; |
|
| 470 | 478 | let state = match slot.state { |
|
| 471 | 479 | CommitReviewState::Accepted => Label::from_char(REVIEWED_MARK).fg(palette.positive_fg), |
|
| 472 | 480 | CommitReviewState::Rejected => Label::from_char(REJECTED_MARK).fg(palette.negative_fg), |
|
| 473 | 481 | CommitReviewState::Dropped => Label::from_char(DROPPED_MARK).fg(colors::fixed::MUTED), |
| 911 | 919 | )[4] |
|
| 912 | 920 | .to_string() |
|
| 913 | 921 | .starts_with(IN_PROGRESS_MARK) |
|
| 914 | 922 | ); |
|
| 915 | 923 | ||
| 916 | - | for (state, accepted_lines, expected_color) in [ |
|
| 917 | - | (CommitReviewState::Pending, 0, colors::fixed::MUTED), |
|
| 918 | - | (CommitReviewState::Pending, 1, Color::White), |
|
| 924 | + | for (state, accepted_lines, total_lines, expected_percent, expected_color) in [ |
|
| 925 | + | (CommitReviewState::Pending, 0, 4, 0, Color::White), |
|
| 926 | + | (CommitReviewState::Pending, 1, 4, 25, Color::White), |
|
| 927 | + | (CommitReviewState::Pending, 399, 400, 99, Color::White), |
|
| 919 | 928 | ( |
|
| 920 | - | CommitReviewState::Pending, |
|
| 929 | + | CommitReviewState::Accepted, |
|
| 930 | + | 4, |
|
| 921 | 931 | 4, |
|
| 932 | + | 100, |
|
| 922 | 933 | DiffPalette::default().positive_fg, |
|
| 923 | 934 | ), |
|
| 924 | 935 | ( |
|
| 925 | 936 | CommitReviewState::Rejected, |
|
| 926 | 937 | 0, |
|
| 938 | + | 4, |
|
| 939 | + | 0, |
|
| 927 | 940 | DiffPalette::default().negative_fg, |
|
| 928 | 941 | ), |
|
| 929 | 942 | ] { |
|
| 930 | 943 | slot.state = state; |
|
| 931 | 944 | slot.progress = ReviewProgress { |
|
| 932 | 945 | accepted: accepted_lines, |
|
| 933 | - | total: 4, |
|
| 946 | + | total: total_lines, |
|
| 934 | 947 | }; |
|
| 935 | 948 | slot.total_hunks = 2; |
|
| 936 | 949 | let [_, _, _, _, mut progress, _] = commit_row_suffix( |
|
| 937 | 950 | &slot, |
|
| 938 | 951 | DiffPalette::default(), |
|
| 939 | 952 | now as u64, |
|
| 940 | 953 | stats.insertions + stats.deletions, |
|
| 941 | 954 | 8, |
|
| 942 | 955 | ); |
|
| 943 | - | let percent = slot.progress.filled(100); |
|
| 944 | - | assert!(progress.to_string().contains(&format!("{percent}%/2"))); |
|
| 956 | + | assert!( |
|
| 957 | + | progress |
|
| 958 | + | .to_string() |
|
| 959 | + | .contains(&format!("{expected_percent}%/2")) |
|
| 960 | + | ); |
|
| 945 | 961 | let mut buffer = Buffer::empty(Rect::new(0, 0, 16, 1)); |
|
| 946 | 962 | progress.render(buffer.area(), &mut buffer); |
|
| 947 | - | let slash_col = 2 + percent.to_string().len() + 1; |
|
| 963 | + | let slash_col = 2 + expected_percent.to_string().len() + 1; |
|
| 948 | 964 | ||
| 949 | 965 | let icon_color = match (state, accepted_lines) { |
|
| 950 | 966 | (CommitReviewState::Rejected, _) => DiffPalette::default().negative_fg, |
|
| 967 | + | (CommitReviewState::Accepted, _) => DiffPalette::default().positive_fg, |
|
| 951 | 968 | (CommitReviewState::Pending, 0) => colors::fixed::MUTED, |
|
| 952 | 969 | (CommitReviewState::Pending, _) => Color::White, |
|
| 953 | 970 | _ => unreachable!(), |
|
| 954 | 971 | }; |
|
| 955 | 972 |