diff --git a/codex-rs/tui/src/diff_render.rs b/codex-rs/tui/src/diff_render.rs index ada84b89..9b37846b 100644 --- a/codex-rs/tui/src/diff_render.rs +++ b/codex-rs/tui/src/diff_render.rs @@ -270,13 +270,14 @@ fn push_wrapped_diff_line( // Reserve a fixed number of spaces after the line number so that content starts // at a consistent column. The sign ("+"/"-") is rendered as part of the content - // with the same background as the edit, not as a separate dimmed column. + // and colored with the same foreground as the edited text, not as a separate + // dimmed column. let gap_after_ln = SPACES_AFTER_LINE_NUMBER.saturating_sub(ln_str.len()); let first_prefix_cols = indent.len() + ln_str.len() + gap_after_ln; let cont_prefix_cols = indent.len() + ln_str.len() + gap_after_ln; let mut first = true; - let (sign_opt, bg_style) = match kind { + let (sign_opt, line_style) = match kind { DiffLineType::Insert => (Some('+'), Some(style_add())), DiffLineType::Delete => (Some('-'), Some(style_del())), DiffLineType::Context => (None, None), @@ -307,18 +308,22 @@ fn push_wrapped_diff_line( spans.push(RtSpan::raw(" ".repeat(gap_after_ln))); // Prefix the content with the sign if it is an insertion or deletion, and color - // the sign with the same background as the edited text. + // the sign and content with the same foreground as the edited text. let display_chunk = match sign_opt { Some(sign_char) => format!("{sign_char}{chunk}"), None => chunk.to_string(), }; - let content_span = match bg_style { + let content_span = match line_style { Some(style) => RtSpan::styled(display_chunk, style), None => RtSpan::raw(display_chunk), }; spans.push(content_span); - lines.push(RtLine::from(spans)); + let mut line = RtLine::from(spans); + if let Some(style) = line_style { + line.style = line.style.patch(style); + } + lines.push(line); first = false; } else { let hang_prefix = format!( @@ -326,11 +331,15 @@ fn push_wrapped_diff_line( " ".repeat(ln_str.len()), " ".repeat(gap_after_ln) ); - let content_span = match bg_style { + let content_span = match line_style { Some(style) => RtSpan::styled(chunk.to_string(), style), None => RtSpan::raw(chunk.to_string()), }; - lines.push(RtLine::from(vec![RtSpan::raw(hang_prefix), content_span])); + let mut line = RtLine::from(vec![RtSpan::raw(hang_prefix), content_span]); + if let Some(style) = line_style { + line.style = line.style.patch(style); + } + lines.push(line); } } lines @@ -341,11 +350,11 @@ fn style_dim() -> Style { } fn style_add() -> Style { - Style::default().bg(Color::Green) + Style::default().fg(Color::Green) } fn style_del() -> Style { - Style::default().bg(Color::Red) + Style::default().fg(Color::Red) } #[allow(clippy::expect_used)]