Skip to content

Interactive compare mode: live review with pause/diff/skip controls #12

@djdarcy

Description

@djdarcy

Interactive compare mode: live review with pause/diff/skip controls

Problem

The compare command currently runs as a batch process -- it compares all files, shows results at the end, and only then can the user review. For users with many files, this means waiting for the full comparison to finish before seeing anything actionable.

With the progress bar now showing per-file and per-fuzzy-candidate detail (window01\tab09.txt [fuzzy 47/154]), users can see what's happening but can't intervene. If they spot a file being fuzzy-compared that they know isn't relevant, they can't skip it. If they see an interesting near-match, they can't pause and diff it immediately.

Proposed solution

Add --interactive / -i flag to compare that enables live controls during comparison:

notepad-cleanup compare <folder> -s "..." --interactive

During processing, the status line shows available actions:

⠇ Comparing... ━━━━━━╺━━━━━ 23/93 window07\tab02.txt [fuzzy 88/154]
  [(p)ause  (s)kip file  (d)iff  (q)uit]

Controls:

  • (p)ause -- Pause processing. Shows the current file's comparison details (which files it's being compared against, current best near-match if any). Resume with Enter
  • (s)kip -- Skip the current file entirely, mark as "new" regardless of fuzzy results. Useful when the user knows a file isn't a real near-match
  • (d)iff -- Launch the configured diff tool (Beyond Compare, etc.) for the current file vs. its best near-match candidate so far. Processing pauses while diff tool is open
  • (q)uit -- Stop comparison early. Files processed so far are reported normally; unprocessed files are listed as "not compared"

Design considerations

  • Non-blocking key detection: On Windows, msvcrt.kbhit() + msvcrt.getch() can detect keypresses without blocking. On Unix, select.select() on stdin. This needs to be platform-aware
  • Rich progress bar interaction: Rich's Progress context manager owns the terminal. Key detection must work alongside it without corrupting the display. May need to use Rich's Live display instead of Progress
  • Batch mode is the default: --interactive is opt-in. Scripts and CI get the current batch behavior. This also means the progress_callback API stays the same for batch mode
  • Diff tool mid-stream: When the user presses d, we need to (1) pause the inner loop, (2) identify the current best candidate, (3) launch the diff tool, (4) wait for it to close or not, (5) resume. The diff tool should launch in the background (user may want to keep it open while resuming comparison)
  • Skip feedback: When a user skips a file, it should be noted in the results output: "window07\tab02.txt (skipped by user)" so there's a record of the intervention

Implementation approach

  • Add --interactive / -i flag to compare command in cli.py
  • Add InteractiveController class that wraps the progress callback and handles key detection
  • Modify find_duplicates to accept an optional control_callback that can return "continue", "skip", or "quit" -- checked at each iteration
  • Platform-specific key detection: msvcrt on Windows, termios + select on Unix
  • The diff tool integration reuses the existing resolve_diff_tool() / launch_diff_tool() from dedup.py

Acceptance criteria

  • --interactive flag added to compare command
  • Keypress detection works on Windows (msvcrt)
  • (p)ause pauses processing and shows current state
  • (s)kip marks current file as new and moves to next
  • (d)iff launches configured diff tool for current file vs best candidate
  • (q)uit stops early with partial results
  • Default (no -i) behavior unchanged (batch mode)
  • Skipped files noted in output as user-skipped
  • Works alongside Rich progress display without corruption

Related issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions