package miaou-driver-matrix

  1. Overview
  2. Docs

Module Miaou_driver_matrix.Matrix_selectionSource

Terminal text selection for the Matrix driver.

Handles mouse-based text selection with visual highlighting and clipboard integration. Selection works globally across any rendered content - no widget-specific code required.

Usage:

  let selection = Matrix_selection.create () in
  (* On mouse press: *)
  Matrix_selection.start_selection selection ~row ~col ~get_char ~cols ;
  (* On mouse drag: *)
  Matrix_selection.update_selection selection ~row ~col ;
  (* On mouse release: *)
  match Matrix_selection.finish_selection selection ~get_char ~cols with
  | Some text -> Matrix_selection.copy_to_clipboard text
  | None -> ()

Selection is drawn using reverse video style as an overlay on the normal buffer content.

Sourcetype t

Selection state.

Sourceval create : unit -> t

Create a new selection state (no active selection).

Sourceval is_active : t -> bool

Whether a selection drag is currently in progress.

Sourceval has_selection : t -> bool

Whether there is a non-empty selection (even if drag finished).

Sourceval is_single_point : t -> bool

Whether the selection is a single point (single click, no drag). Used to distinguish clicks from text selection.

Sourceval is_multi_click : t -> bool

Whether this is a multi-click (double or triple click). Used to pass double-clicks to widgets.

Sourceval click_count : t -> int

Get the click count (1 = single, 2 = double, 3 = triple).

Sourceval is_selected : t -> row:int -> col:int -> bool

Check if a cell at (row, col) is within the current selection.

Sourceval start_selection : t -> row:int -> col:int -> get_char:(row:int -> col:int -> string) -> cols:int -> unit

Start a new selection at the given position (on mouse press). Detects double-click (select word) and triple-click (select line).

  • parameter get_char

    Function to get character at (row, col) from buffer

  • parameter cols

    Number of columns in the buffer

Sourceval update_selection : t -> row:int -> col:int -> unit

Update the selection endpoint (on mouse drag).

Sourceval finish_selection : t -> get_char:(row:int -> col:int -> string) -> cols:int -> string option

Finish selection and extract the selected text.

  • parameter get_char

    Function to get character at (row, col) from buffer

  • parameter cols

    Number of columns in the buffer

  • returns

    Selected text with trailing spaces trimmed, or None if no selection

Sourceval clear : t -> unit

Clear the current selection.

Sourceval apply_highlight : t -> set_style:(row:int -> col:int -> reverse:bool -> unit) -> rows:int -> cols:int -> unit

Apply selection highlight overlay to buffer cells. Cells within selection have their reverse style set.

  • parameter set_style

    Function to modify cell style at (row, col)

  • parameter rows

    Number of rows in buffer

  • parameter cols

    Number of columns in buffer

Sourceval copy_to_clipboard : string -> unit

Copy text to system clipboard using the Clipboard capability. Does nothing if Clipboard capability is not registered.