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.
MultiSelectPanel is a richer sibling for panels that need multiple
selection regions, keyboard extension, owned scrolling with drag
auto-scroll, and styled (syntax-highlighted) content.
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.clipboard—copy_to_clipboard(local tool + OSC 52 fallback), plusset_clipboard_modeto pin or disable the mechanism.wrap— the underlying character-exact line-wrapping helpers.
§Optional scrollbar
With the default-on scrollbar feature, scrollbar adds a
panel-agnostic vertical scrollbar: scroll_for_track_row maps a
track click/drag to a scroll offset and render_scrollbar draws the
thumb. MultiSelectPanel gains scroll_to_track_row /
render_scrollbar convenience wrappers that plumb their own geometry in.
Re-exports§
pub use clipboard::ClipboardMode;pub use clipboard::set_clipboard_mode;pub use multiselect::AutoScroll;pub use multiselect::Motion;pub use multiselect::MultiSelectPanel;pub use panel::MouseAction;pub use panel::MouseConfig;pub use panel::SelectablePanel;pub use scrollbar::ScrollbarStyle;pub use scrollbar::render_scrollbar;pub use scrollbar::scroll_for_track_row;pub use terminal::TerminalGuard;pub use wrapcache::PanelWrap;pub use wrapcache::TextPos;pub use wrapcache::WrapMarker;pub use wrapcache::WrapMode;
Modules§
- clipboard
- Copy-on-mouse-up for panel-scoped text selection.
- multiselect
- A batteries-included, multi-region text panel:
MultiSelectPanel. - panel
- A ready-to-use, batteries-included wrapper:
SelectablePanel. - scrollbar
- Optional vertical scrollbar helpers, gated behind the
scrollbarfeature. - 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.