37 lines
1.1 KiB
Rust
37 lines
1.1 KiB
Rust
//! The terminal file viewer: one OS window per clicked path.
|
|||
|
|
//!
|
||
|
|
//! Every window is a `file-viewer-<n>` label registered in [`registry::ViewerRegistry`];
|
||
|
|
//! the commands in `commands/file_viewer_commands.rs` gate on the label and act only on
|
||
|
|
//! the caller's own entry, which is why nothing here takes a path from a window.
|
||
|
|
|
||
|
|
pub mod poll;
|
||
|
|
pub mod registry;
|
||
|
|
pub mod resolve;
|
||
|
|
pub mod window;
|
||
|
|
pub mod write;
|
||
|
|
|
||
|
|
/// Spec §3: the 21st click is refused with a toast.
|
||
|
|
pub const MAX_VIEWER_WINDOWS: usize = 20;
|
||
|
|
pub const VIEWER_LABEL_PREFIX: &str = "file-viewer-";
|
||
|
|
|
||
|
|
pub fn is_viewer_label(label: &str) -> bool {
|
||
|
|
label
|
||
|
|
.strip_prefix(VIEWER_LABEL_PREFIX)
|
||
|
|
.is_some_and(|rest| !rest.is_empty() && rest.bytes().all(|b| b.is_ascii_digit()))
|
||
|
|
}
|
||
|
|
|
||
|
|
#[cfg(test)]
|
||
|
|
mod tests {
|
||
|
|
use super::*;
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn only_numbered_viewer_labels_pass() {
|
||
|
|
assert!(is_viewer_label("file-viewer-1"));
|
||
|
|
assert!(is_viewer_label("file-viewer-20"));
|
||
|
|
assert!(!is_viewer_label("file-viewer-"));
|
||
|
|
assert!(!is_viewer_label("file-viewer-x"));
|
||
|
|
assert!(!is_viewer_label("main"));
|
||
|
|
assert!(!is_viewer_label("browser-view-abc"));
|
||
|
|
}
|
||
|
|
}
|