tui_panel_select/lib.rs
1//! Panel-scoped text selection and clipboard copy for [ratatui] apps.
2//!
3//! A terminal's own click-drag selection can't be confined to one panel — it
4//! spans the full terminal row, sweeping up borders and neighbouring panels.
5//! This crate lets an app capture the mouse itself and implement its own
6//! selection that is **confined to a single panel's rectangle**, uses natural
7//! "stream" semantics (never a rectangular block), **survives resizes,
8//! rewraps and scrolling** (selections are stored as logical line/column
9//! positions, not stale screen cells), and stays cheap even for
10//! multi-megabyte content (only what's on screen is ever wrapped or painted).
11//! On mouse-up the selected text is copied to the system clipboard, working
12//! both on a local desktop and over SSH/tmux (OSC 52 fallback).
13//!
14//! # Two ways to use it
15//!
16//! **Batteries-included:** [`SelectablePanel`] bundles the cache and
17//! selection state into one object with a tiny API — `set_content`,
18//! `begin_selection`, `extend_selection`, `selected_text`, `copy_selection`,
19//! `highlight_cells`, `visible_rows`. See its module for a worked example.
20//!
21//! **Primitives:** if your app already owns its selection state (e.g. you
22//! support multiple simultaneous selections or keyboard extension), use the
23//! stateless building blocks directly:
24//! - [`PanelWrap`] / [`TextPos`] — the line/wrap cache and logical positions
25//! ([`wrapcache`]).
26//! - [`selection`] — pure functions: `point_to_textpos`, `extract_text`,
27//! `highlight_cells`, `strip_positions`.
28//! - [`clipboard`] — `copy_to_clipboard` (local tool + OSC 52 fallback).
29//! - [`wrap`] — the underlying character-exact line-wrapping helpers.
30//!
31//! [ratatui]: https://docs.rs/ratatui
32
33pub mod clipboard;
34pub mod panel;
35pub mod selection;
36#[cfg(feature = "terminal-guard")]
37pub mod terminal;
38pub mod wrap;
39pub mod wrapcache;
40
41pub use panel::{MouseAction, MouseConfig, SelectablePanel};
42#[cfg(feature = "terminal-guard")]
43pub use terminal::TerminalGuard;
44pub use wrapcache::{PanelWrap, TextPos};