Skip to content

fix(tui): strip CRLF artifacts in diff view#9517

Open
conqueror wants to merge 1 commit intoopenai:mainfrom
conqueror:fix/crlf-diff-render
Open

fix(tui): strip CRLF artifacts in diff view#9517
conqueror wants to merge 1 commit intoopenai:mainfrom
conqueror:fix/crlf-diff-render

Conversation

@conqueror
Copy link
Copy Markdown

@conqueror conqueror commented Jan 20, 2026

Summary

  • strip trailing carriage returns when rendering diff lines to avoid CRLF artifacts
  • add regression tests for CRLF diff rendering in tui/tui2

Testing

  • just fmt
  • cargo test -p codex-tui
  • cargo test -p codex-tui2
  • just fix -p codex-tui
  • just fix -p codex-tui2

Fixes #9455

@etraut-openai
Copy link
Copy Markdown
Collaborator

Thanks for the PR.

I don't know that this is the correct fix for this bug. This is papering over the underlying problem.

I'll discuss with my colleagues and see what they think.

@etraut-openai
Copy link
Copy Markdown
Collaborator

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown
Contributor

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@nidhishgajjar
Copy link
Copy Markdown

Orb Code Review (powered by GLM-4.7 on Orb Cloud)

Summary

This PR fixes a display issue in the TUI diff view where CRLF (Carriage Return + Line Feed) line endings from Windows-style files would cause rendering artifacts. The fix strips trailing carriage returns (\r) from diff text before rendering, ensuring clean display regardless of the original file's line ending format.

Architecture

The fix:

  1. Added trim_end_matches('\r') to strip carriage returns:
// Before:
let mut remaining_text: &str = text;

// After:
let mut remaining_text: &str = text.trim_end_matches('\r');
  1. Applied to both TUI implementations:

    • codex-rs/tui/src/diff_render.rs
    • codex-rs/tui2/src/diff_render.rs
  2. Added comprehensive test:

#[test]
fn trims_crlf_in_diff_output() {
    let original = "one\r\ntwo\r\n";
    let modified = "one\r\nTWO\r\n";
    let patch = diffy::create_patch(original, modified).to_string();
    
    // Test update, add, and delete operations
    changes.insert(PathBuf::from("crlf_update.txt"), FileChange::Update { ... });
    changes.insert(PathBuf::from("crlf_add.txt"), FileChange::Add { content: "alpha\r\nbeta\r\n".to_string() });
    changes.insert(PathBuf::from("crlf_delete.txt"), FileChange::Delete { content: "gamma\r\ndelta\r\n".to_string() });
    
    let lines = diff_summary_for_tests(&changes);
    let text = lines.iter().map(|l| l.spans.iter().map(|s| s.content.as_ref()).collect::<String>()).collect::<Vec<_>>().join("\n");
    
    assert_eq!(text.contains('\r'), false);
}

The problem:
Files created on Windows use CRLF (\r\n) line endings, while Unix/Linux systems use LF (\n) only. When displaying these files in the TUI diff view, the carriage return character (\r) would cause rendering issues, making the diff difficult to read.

The solution:
Strip trailing carriage returns from each line before rendering, ensuring clean display regardless of the original file's line ending format.

Issues

No issues found.

This is a well-executed bug fix that:

  1. Solves real cross-platform issue: Windows users will see clean diffs regardless of file line endings

  2. Minimal and focused: Single-line change in the right location

  3. Comprehensive test: Tests all file operations (update, add, delete) with CRLF content

  4. Applied consistently: Fixed in both TUI implementations (tui and tui2)

  5. Correct approach: Uses trim_end_matches('\r') which only removes trailing carriage returns, not all carriage returns in the text

Cross-file Impact

Affected components:

  • codex-rs/tui/src/diff_render.rs — Added CRLF stripping (44 insertions, 1 deletion)
  • codex-rs/tui2/src/diff_render.rs — Added CRLF stripping (44 insertions, 1 deletion)

Breaking changes: None. This is a display bug fix.

Behavior changes:

  • Before: Diff view would show rendering artifacts for Windows-style files with CRLF line endings
  • After: Diff view cleanly displays files regardless of line ending format (CRLF or LF)

Cross-platform impact:

  • Positive: Improves display quality for Windows users and files created on Windows
  • No negative impact: Unix/Linux files (LF only) are unaffected by the trim operation

Assessment

✅ Approve

Simple but effective fix for a real cross-platform display issue:

Strengths:

  • Solves a genuine user experience problem for Windows users
  • Minimal and focused change
  • Comprehensive test coverage
  • Consistent application across both TUI implementations
  • Correct use of trim_end_matches('\r')

User benefit:
Users working with files that have Windows-style line endings will now see clean, readable diffs in the TUI instead of rendering artifacts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Diff view shows a lot of line ending changes

3 participants