Skip to content

Commit f9676db

Browse files
committed
feat: add interactive review mode
- Added --review flag for directory diffs - Users can now step through differences in the terminal - Interactive prompt to accept/overwrite baseline or skip - Integrated terminal previews during review
1 parent 022fb04 commit f9676db

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pathdiff = "0.2.1"
1818
serde = { version = "1.0.200", features = ["derive"] }
1919
serde_json = "1.0.116"
2020
image-compare = "0.5.0"
21+
dialoguer = "0.11.0"
2122

2223
[dev-dependencies]
2324
tempfile = "3.10.1"

src/main.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ struct Args {
5252
#[arg(long)]
5353
json: bool,
5454

55+
/// Interactive review mode for directory diffs
56+
#[arg(long)]
57+
review: bool,
58+
5559
/// Ignore regions in format x,y,width,height (can be used multiple times)
5660
#[arg(short, long, value_delimiter = ' ')]
5761
ignore: Vec<Region>,
@@ -174,6 +178,50 @@ fn run_dir_diff(args: &Args) -> Result<()> {
174178
items.len(),
175179
diff_count
176180
);
181+
182+
if args.review && diff_count > 0 {
183+
use dialoguer::Select;
184+
println!("\n{}", "Entering Review Mode...".bold().yellow());
185+
186+
for item in items {
187+
if let dir::DirDiffStatus::Match(res) = &item.status {
188+
if res.diff_pixels > 0 {
189+
println!("\n{}", "-".repeat(40));
190+
println!("Reviewing: {}", item.relative_path.display().to_string().bold().cyan());
191+
println!("Pixel Similarity: {:.2}%", res.score * 100.0);
192+
193+
// Regenerate diff for preview
194+
let full_res = compare::compare_images(
195+
&args.path_a.join(&item.relative_path),
196+
&args.path_b.join(&item.relative_path),
197+
args.threshold,
198+
true,
199+
&args.ignore,
200+
args.mask.as_deref(),
201+
)?;
202+
203+
if let Some(diff_img) = full_res.diff_image {
204+
println!("{}", "Terminal Preview (Heatmap):".dimmed());
205+
terminal::print_preview(&image::DynamicImage::ImageRgba8(diff_img));
206+
}
207+
208+
let selections = &["Keep Original", "Accept New (Overwrite Original)", "Skip"];
209+
let selection = Select::new()
210+
.with_prompt("Action")
211+
.default(0)
212+
.items(&selections[..])
213+
.interact()?;
214+
215+
if selection == 1 {
216+
let src = args.path_b.join(&item.relative_path);
217+
let dst = args.path_a.join(&item.relative_path);
218+
std::fs::copy(&src, &dst)?;
219+
println!("{}", "✓ Baseline updated.".green());
220+
}
221+
}
222+
}
223+
}
224+
}
177225
}
178226

179227
if args.fail_on_diff && diff_count > 0 {

0 commit comments

Comments
 (0)