Skip to main content

slurp_rs/
lib.rs

1//! `slurp-rs` is a Rust implementation of `slurp` with:
2//! - CLI compatibility (`run_cli`)
3//! - reusable typed API (`select_*`)
4//!
5//! # API Quick Start
6//!
7//! ```rust
8//! use slurp_rs::{AspectRatio, LockPolicy, SelectOptions, SlurpError, select_region};
9//!
10//! let options = SelectOptions {
11//!     aspect_ratio: Some(AspectRatio { width: 0, height: 9 }),
12//!     lock_policy: LockPolicy::Disabled,
13//!     ..SelectOptions::default()
14//! };
15//!
16//! let err = select_region(options).unwrap_err();
17//! assert!(matches!(err, SlurpError::InvalidInput(_)));
18//! ```
19//!
20//! # Validate Input Without Wayland
21//!
22//! ```rust
23//! use slurp_rs::{SelectOptions, SlurpError, select_from_boxes};
24//!
25//! let err = select_from_boxes(Vec::new(), SelectOptions::default()).unwrap_err();
26//! assert!(matches!(err, SlurpError::InvalidInput(_)));
27//! ```
28//!
29//! # CLI Entry
30//!
31//! ```rust
32//! use std::process::ExitCode;
33//! use slurp_rs::run_cli;
34//!
35//! let args = vec!["slurp-rs".to_string(), "-h".to_string()];
36//! assert_eq!(run_cli(&args), ExitCode::SUCCESS);
37//! ```
38
39mod backend;
40mod cli;
41mod format;
42mod input;
43mod lock;
44mod slurp_box;
45
46pub mod api;
47pub mod error;
48pub mod types;
49
50pub use api::{SelectRequest, run_cli, select, select_from_boxes, select_output, select_region};
51pub use error::SlurpError;
52pub use types::{
53    AspectRatio, ChoiceBox, Colors, LockPolicy, Rect, SelectOptions, Selection, SelectionKind,
54};
55
56#[cfg(test)]
57mod tests;