diff: Dim commit trailers
38e35d9442eeaab4784e6b678cd71177c7a594bf
Render the final trailer block in a subtle grey so commit metadata remains visually distinct from the message body. Assisted-by: Codex:gpt-5.6
1 parent
72c27cfc
crates/diff/src/viewer.rs
+31 -1
| 1756 | 1756 | .collect::<Vec<_>>(); |
|
| 1757 | 1757 | let message = { |
|
| 1758 | 1758 | let first_non_empty = message_lines.iter().position(|text| !text.is_empty()); |
|
| 1759 | 1759 | let last_non_empty = message_lines.iter().rposition(|text| !text.is_empty()); |
|
| 1760 | 1760 | if let (Some(start), Some(end)) = (first_non_empty, last_non_empty) { |
|
| 1761 | - | message_lines[start..=end] |
|
| 1761 | + | let lines = &message_lines[start..=end]; |
|
| 1762 | + | let trailer_start = lines |
|
| 1763 | + | .iter() |
|
| 1764 | + | .rposition(|text| text.is_empty()) |
|
| 1765 | + | .map(|index| index + 1) |
|
| 1766 | + | .filter(|&index| { |
|
| 1767 | + | index < lines.len() |
|
| 1768 | + | && lines[index..] |
|
| 1769 | + | .iter() |
|
| 1770 | + | .try_fold(false, |has_trailer, text| { |
|
| 1771 | + | if text.as_bytes().first().is_some_and(u8::is_ascii_whitespace) |
|
| 1772 | + | { |
|
| 1773 | + | has_trailer.then_some(true) |
|
| 1774 | + | } else { |
|
| 1775 | + | text.split_once(':') |
|
| 1776 | + | .is_some_and(|(key, value)| { |
|
| 1777 | + | !key.is_empty() |
|
| 1778 | + | && !value.trim().is_empty() |
|
| 1779 | + | && key.chars().all(|character| { |
|
| 1780 | + | character.is_ascii_alphanumeric() |
|
| 1781 | + | || character == '-' |
|
| 1782 | + | }) |
|
| 1783 | + | }) |
|
| 1784 | + | .then_some(true) |
|
| 1785 | + | } |
|
| 1786 | + | }) |
|
| 1787 | + | .is_some() |
|
| 1788 | + | }); |
|
| 1789 | + | lines |
|
| 1762 | 1790 | .iter() |
|
| 1763 | 1791 | .enumerate() |
|
| 1764 | 1792 | .map(|(index, &text)| { |
|
| 1765 | 1793 | let line = if text.is_empty() { |
|
| 1766 | 1794 | Line::blank() |
|
| 1767 | 1795 | } else { |
|
| 1768 | 1796 | Line::new(text.to_owned()) |
|
| 1769 | 1797 | }; |
|
| 1770 | 1798 | if index == 0 { |
|
| 1771 | 1799 | line.style(Style::default().bold()) |
|
| 1800 | + | } else if trailer_start.is_some_and(|start| index >= start) { |
|
| 1801 | + | line.style(Style::new(colors::rgb::DIM)) |
|
| 1772 | 1802 | } else { |
|
| 1773 | 1803 | line |
|
| 1774 | 1804 | } |
|
| 1775 | 1805 | }) |
|
| 1776 | 1806 | .collect() |
a.rs
+0 -0
a.rs
+0 -0
b.rs
+0 -0
a.rs
+0 -0
a.rs
+0 -0
a.rs
+0 -0
b.rs
+0 -0
crates/diff/tests/golden/sticky_header_before_next_file_64x5.txt
+0 -0
src/a.rs
+0 -0
src/b.rs
+0 -0
README.md
+0 -0
src/app/a.rs
+0 -0
src/lib/b.rs
+0 -0
README.md
+0 -0
a.rs
+0 -0
b.rs
+0 -0
assets/css/style.css
+0 -0
assets/css/style.css
+0 -0
first.rs
+0 -0
second.rs
+0 -0
a.rs
+0 -0
a.rs
+0 -0
a.rs
+0 -0
a.rs
+0 -0
b.rs
+0 -0
a.rs\n",
+0 -0
a\n\
+0 -0