Skip to main content

Crate tui_panel_select

Crate tui_panel_select 

Source
Expand description

Panel-scoped text selection and clipboard copy for ratatui apps.

A terminal’s own click-drag selection can’t be confined to one panel — it spans the full terminal row, sweeping up borders and neighbouring panels. This crate lets an app capture the mouse itself and implement its own selection that is confined to a single panel’s rectangle, uses natural “stream” semantics (never a rectangular block), survives resizes, rewraps and scrolling (selections are stored as logical line/column positions, not stale screen cells), and stays cheap even for multi-megabyte content (only what’s on screen is ever wrapped or painted). On mouse-up the selected text is copied to the system clipboard, working both on a local desktop and over SSH/tmux (OSC 52 fallback).

§Two ways to use it

Batteries-included: SelectablePanel bundles the cache and selection state into one object with a tiny API — set_content, begin_selection, extend_selection, selected_text, copy_selection, highlight_cells, visible_rows. See its module for a worked example.

Primitives: if your app already owns its selection state (e.g. you support multiple simultaneous selections or keyboard extension), use the stateless building blocks directly:

  • PanelWrap / TextPos — the line/wrap cache and logical positions (wrapcache).
  • selection — pure functions: point_to_textpos, extract_text, highlight_cells, strip_positions.
  • clipboardcopy_to_clipboard (local tool + OSC 52 fallback).
  • wrap — the underlying character-exact line-wrapping helpers.

Re-exports§

pub use panel::MouseAction;
pub use panel::MouseConfig;
pub use panel::SelectablePanel;
pub use terminal::TerminalGuard;
pub use wrapcache::PanelWrap;
pub use wrapcache::TextPos;

Modules§

clipboard
Copy-on-mouse-up for panel-scoped text selection.
panel
A ready-to-use, batteries-included wrapper: SelectablePanel.
selection
Mouse (and keyboard-extended) text selection scoped to a single panel (Request JSON / Response).
terminal
Panic-safe terminal setup for mouse capture (feature terminal-guard).
wrap
Character-exact line wrapping primitives.
wrapcache
Shared line/wrap-structure cache backing both the Request JSON and Response panels’ rendering and their text selection.