Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
selection-capture
selection-capture is a Rust library for selected-text capture with retry, cancellation,
and strategy fallbacks.
It is designed as a replacement foundation for earlier get-selected-text style usage,
with explicit capture status and trace metadata for app-level UX decisions.
Features
- โ Synchronous API - Simple, blocking calls that are easy to integrate
- ๐ Retry Logic - Automatic retry with configurable budgets and delays
- โก Multiple Strategies - Falls back through different capture methods automatically
- ๐ฏ App-Specific Profiles - Customize behavior per application
- ๐ Detailed Tracing - Full visibility into what happened during capture attempts
- โ Cancellation Support - Cooperative cancellation via
CancelSignaltrait - ๐งน Automatic Cleanup - Clipboard cleanup after capture
Platform Support
- macOS: Fully implemented (
MacOSPlatform) - Other platforms: Portable API via
CapturePlatformtrait, implementations welcome!
Installation
Add this to your Cargo.toml:
[]
= "0.1"
Or use the latest from Git:
[]
= { = "https://github.com/maemreyo/selection-capture" }
Quick Start (macOS)
use ;
// Implement required traits for your use case
;
;
Core API
Main Function
capture(...)โCaptureOutcome- The primary capture function
Configuration
CaptureOptions- Configure timeouts, trace collection, and strategy overridesCapturePlatform- Trait for platform-specific implementationsCancelSignal- Trait for cooperative cancellationAppAdapter- Trait for app-specific customizationsAppProfileStore- Trait for persisting app profiles
Return Types
CaptureOutcome::{Success, Failure}- Result of capture attemptCaptureStatus- Detailed status codes for deterministic UX mappingFailureKind- Categorization of failure modesCaptureTrace- Complete trace of all attempts made
Example with Custom Options
let options = CaptureOptions ;
Permission Notes (macOS)
Depending on the target application and capture strategy, users may need to grant:
-
Accessibility Permission
System Settings โ Privacy & Security โ Accessibility -
Automation Permission
Required for AppleScript fallback in some application combinations
The library will gracefully degrade through available strategies based on permissions.
Architecture
โโโโโโโโโโโโโโโโโโโ
โ capture() โ
โโโโโโโโโโฌโโโโโโโโโ
โ
โโโโโโผโโโโโ
โ Strategy โ
โ Manager โ
โโโโโโฌโโโโโ
โ
โโโโโโผโโโโโโโโโโโโโโโโโโ
โ 1. Accessibility API โ โ Primary method
โโโโโโโโโโโโโโโโโโโโโโโโค
โ 2. AppleScript โ โ Fallback 1
โโโโโโโโโโโโโโโโโโโโโโโโค
โ 3. Clipboard Monitor โ โ Fallback 2
โโโโโโโโโโโโโโโโโโโโโโโโ
Each strategy is attempted in order, with automatic retry and detailed tracing.
Contributing
Contributions are welcome! Please see our Contributing Guide for details on:
- Reporting bugs
- Suggesting features
- Submitting pull requests
- Code style and testing
Development Setup
# Clone the repository
# Build
# Run tests
# Check formatting
# Run linter
Documentation
Related Projects
This library was extracted from the zmr-koe project, which provides a complete text capture solution.
License
MIT License - See LICENSE file for details.
Acknowledgments
Thanks to all contributors and the Rust community for making this possible!
Built with โค๏ธ by zamery and contributors