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//! [`MultiSelectPanel`] is a richer sibling for panels that need **multiple
21//! selection regions**, **keyboard extension**, **owned scrolling with drag
22//! auto-scroll**, and **styled (syntax-highlighted) content**.
23//!
24//! **Primitives:** if your app already owns its selection state (e.g. you
25//! support multiple simultaneous selections or keyboard extension), use the
26//! stateless building blocks directly:
27//! - [`PanelWrap`] / [`TextPos`] — the line/wrap cache and logical positions
28//! ([`wrapcache`]).
29//! - [`selection`] — pure functions: `point_to_textpos`, `extract_text`,
30//! `highlight_cells`, `strip_positions`.
31//! - [`clipboard`] — `copy_to_clipboard` (local tool + OSC 52 fallback).
32//! - [`wrap`] — the underlying character-exact line-wrapping helpers.
33//!
34//! [ratatui]: https://docs.rs/ratatui
35
36pub mod clipboard;
37pub mod multiselect;
38pub mod panel;
39pub mod selection;
40#[cfg(feature = "terminal-guard")]
41pub mod terminal;
42pub mod wrap;
43pub mod wrapcache;
44
45pub use multiselect::{AutoScroll, Motion, MultiSelectPanel};
46pub use panel::{MouseAction, MouseConfig, SelectablePanel};
47#[cfg(feature = "terminal-guard")]
48pub use terminal::TerminalGuard;
49pub use wrapcache::{PanelWrap, TextPos, WrapMarker, WrapMode};