Module diff

Module diff 

Source
Expand description

Code diffing widget

This module provides the DiffWidget for displaying and managing code changes. It supports multiple diff formats (unified and side-by-side), syntax highlighting, and hunk-level approval/rejection.

§Features

  • Multiple view formats: Unified and side-by-side diff views
  • Syntax highlighting: Language-aware code highlighting
  • Hunk navigation: Jump between hunks with keyboard shortcuts
  • Approval workflow: Accept or reject individual hunks
  • Line numbers: Display original and new line numbers

§Examples

Creating a diff widget:

use ricecoder_tui::{DiffWidget, DiffHunk, DiffLine, DiffLineType};

let mut diff = DiffWidget::new();
let line = DiffLine {
    line_type: DiffLineType::Added,
    old_line_num: None,
    new_line_num: Some(1),
    content: "fn hello() {}".to_string(),
};

Navigating hunks:

diff.next_hunk();  // Move to next hunk
diff.prev_hunk();  // Move to previous hunk

Approving changes:

diff.approve_hunk(0);  // Approve first hunk
diff.reject_hunk(1);   // Reject second hunk

Structs§

DiffHunk
Diff hunk
DiffLine
Diff line
DiffWidget
Diff widget

Enums§

DiffLineType
Diff line type
DiffViewType
Diff view type