package miaou-core

  1. Overview
  2. Docs
On This Page
  1. Usage
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module Miaou_helpers.MouseSource

Mouse event parsing utilities for widgets.

Provides helpers to parse mouse key strings dispatched by drivers (e.g., "Mouse:5:10", "MouseDrag:3:7", "WheelUp", "WheelDown").

Usage

  let handle_key t ~key =
    if Mouse.is_wheel_up key then
      scroll_up t Mouse.wheel_scroll_lines
    else if Mouse.is_wheel_down key then
      scroll_down t Mouse.wheel_scroll_lines
    else
      match Mouse.parse_click key with
      | Some {row; col} -> handle_click t ~row ~col
      | None -> (* not a mouse event *) t
Sourcetype mouse_event = {
  1. row : int;
  2. col : int;
}

Mouse click/drag event with terminal coordinates (1-indexed).

Sourceval parse_click : string -> mouse_event option

Parse a "Mouse:row:col", "DoubleClick:row:col", "TripleClick:row:col", or "MouseDrag:row:col" key string.

  • returns

    Some {row; col} if valid, None otherwise.

Sourceval is_click : string -> bool

Check if key is a mouse click event ("Mouse:...").

Sourceval is_double_click : string -> bool

Check if key is a double-click event ("DoubleClick:...").

Sourceval is_triple_click : string -> bool

Check if key is a triple-click event ("TripleClick:...").

Sourceval is_drag : string -> bool

Check if key is a mouse drag event ("MouseDrag:...").

Sourceval is_wheel_up : string -> bool

Check if key is a wheel up event ("WheelUp").

Sourceval is_wheel_down : string -> bool

Check if key is a wheel down event ("WheelDown").

Sourceval is_wheel : string -> bool

Check if key is any wheel event (up or down).

Sourceval is_mouse_event : string -> bool

Check if key is any mouse-related event (click, drag, or wheel).

Sourceval wheel_scroll_lines : int

Default scroll amount for wheel events (number of lines). Currently set to 3.

Sourceval translate_key : row_offset:int -> col_offset:int -> string -> string

Translate mouse coordinates by subtracting offsets. Used to convert screen-absolute coordinates to widget-relative coordinates. For click/drag events: subtracts row_offset from row and col_offset from col. For non-mouse or wheel events: returns the key unchanged.

Example

  (* Modal is at row 5, col 10 on screen *)
  let modal_row = 5 in
  let modal_col = 10 in
  (* Screen click at row 8, col 15 becomes widget-relative row 3, col 5 *)
  let relative_key = Mouse.translate_key ~row_offset:modal_row ~col_offset:modal_col "Mouse:8:15" in
  (* relative_key = "Mouse:3:5" *)