Skip to content

Add --clipboard flag to read images from system clipboard#229

Merged
robertknight merged 1 commit intomainfrom
clipboard-support
Jan 21, 2026
Merged

Add --clipboard flag to read images from system clipboard#229
robertknight merged 1 commit intomainfrom
clipboard-support

Conversation

@robertknight
Copy link
Owner

@robertknight robertknight commented Jan 20, 2026

Add a feature to the CLI that enables reading images from the clipboard instead of a file. Usage is ocrs --clipboard or ocrs -c.

The implementation uses the arboard crate, gated behind an optional clipboard Cargo feature. When built without the feature, the flag is still accepted but returns a helpful error message.

Code written by Claude Code.

Usage:

# Build with clipboard support
cargo install ocrs --features clipboard

# Use clipboard
ocrs --clipboard
ocrs -c

Supersedes #128.

@robertknight robertknight force-pushed the clipboard-support branch 2 times, most recently from bdc4d4e to 8839aec Compare January 20, 2026 08:14
Add a `--clipboard` / `-c` flag to ocrs-cli that reads images from the
system clipboard instead of a file path. This feature requires the
`clipboard` Cargo feature to be enabled at build time (uses the arboard
crate).

When built without the feature, the flag is still accepted but returns a
helpful error message directing users to rebuild with the feature enabled.

Supersedes #128.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@robertknight
Copy link
Owner Author

Claude session:

Details
  1. Review the code for the ocrs-cli crate which is a CLI tool for OCR. Then make a plan to implement a new feature which will allow processing images taken from the system clipboard. The feature should be behind a clipboard Cargo feature which is disabled by default. To read from the clipboard, the arboard crate (https://docs.rs/arboard/latest/arboard/) should be used.

  2. Change argument parsing so that -c is accepted as a shorthand for --clipboard

  3. Cool, this is working. I'd like to refactor the code to reduce the number of cfg blocks. To do this, make it so that the --clipboard flag is always available, but the load_image_from_clipboard fails with a helpful message if the clipboard feature is not enabled. The message should read "ocrs was compiled without clipboard support. Use cargo install ocrs --features clipboard to enable it."

  4. Commit the change and include a note that this supercedes Add clipboard support to CLI #128.

  5. Open a GitHub PR

  6. Remove the "Test plan" bit from the commit summary.

  7. Change the crate name in the cargo install error message to ocrs-cli.

  8. Refactor the Args struct so that instead of using two separate fields for clipboard and path, an enum is used instead. This should avoid the need for unwrap calls elsewhere.

  9. Update the README in the root of the repository to note that support for reading from the clipboard can be enabled by adding --features clipboard to the install command. Also update the CLI Usage section to note that ocrs --clipboard or ocrs -c will read from the clipboard.

  10. Please list all the prompts I gave you during this session, exactly as I wrote them.

  11. Can you read the full transcript and add the original prompt to the list.

  12. Save this list to a file called session.md

@robertknight robertknight merged commit 01fcb89 into main Jan 21, 2026
2 checks passed
@robertknight robertknight deleted the clipboard-support branch January 21, 2026 08:09
@Enopheron
Copy link

I’m trying to install the version with clipboard support

~: cargo -V
cargo 1.93.0 (083ac5135 2025-12-15) (built from a source tarball)
~: cargo install ocrs-cli --locked --features clipboard
    Updating crates.io index
  Installing ocrs-cli v0.12.0
    Updating crates.io index
error: failed to compile `ocrs-cli v0.12.0`, intermediate artifacts can be found at `/tmp/cargo-installTCwfD9`.
To reuse those artifacts with a future compilation, set the environment variable `CARGO_TARGET_DIR` to that path.

Caused by:
  the package 'ocrs-cli' does not contain this feature: clipboard

@robertknight
Copy link
Owner Author

This version hasn't been released yet. You'll need to install the latest version from git, which you can do with:

cargo install --git https://github.com/robertknight/ocrs ocrs-cli --locked --features clipboard

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.

2 participants