Raxol.Terminal.ANSI.MouseEvents (Raxol v0.5.0)

View Source

Handles mouse event reporting for the terminal emulator. Supports various mouse reporting modes including:

  • Basic mouse tracking (mode 1000)
  • Highlight mouse tracking (mode 1001)
  • Cell mouse tracking (mode 1002)
  • All mouse tracking (mode 1003)
  • Focus events (mode 1004)
  • UTF-8 mouse reporting (mode 1005)
  • SGR mouse reporting (mode 1006)
  • URXVT mouse reporting (mode 1015)
  • SGR pixels mouse reporting (mode 1016)

Summary

Functions

Calculates the drag state based on the current and previous mouse states.

Decodes button state and modifiers from a mouse event byte.

Decodes modifier keys from a mouse event byte.

Decodes URXVT button state from a mouse event byte.

Disables mouse tracking.

Enables mouse tracking with the specified mode.

Generates a mouse event report based on the current state.

Creates a new mouse state with default values.

Parses coordinates from a mouse event string.

Parses a mouse event in the format: <button>;<x>;<y>M

Parses an SGR pixels mouse event in the format: <button>;<x>;<y>M

Parses a URXVT mouse event in the format: <button>;<x>;<y>M

Processes a mouse event and returns the updated state and event data. Supports extended mouse reporting modes including SGR pixels and URXVT.

Updates the button state.

Updates the drag state.

Updates the modifiers state.

Updates the mouse position.

Updates the mouse state with new event data.

Types

modifier()

@type modifier() :: :shift | :alt | :ctrl | :meta

mouse_mode()

@type mouse_mode() ::
  :basic
  | :highlight
  | :cell
  | :all
  | :focus
  | :utf8
  | :sgr
  | :urxvt
  | :sgr_pixels

mouse_state()

@type mouse_state() :: %{
  enabled: boolean(),
  mode: mouse_mode(),
  button_state: :none | :left | :middle | :right | :release,
  modifiers: MapSet.t(),
  position: {integer(), integer()},
  last_position: {integer(), integer()},
  drag_state: :none | :dragging | :drag_end
}

Functions

calculate_drag_state(state, event)

@spec calculate_drag_state(mouse_state(), map()) :: :none | :dragging | :drag_end

Calculates the drag state based on the current and previous mouse states.

decode_button(button)

@spec decode_button(integer()) :: :left | :middle | :right | :release

Decodes button state and modifiers from a mouse event byte.

decode_modifiers(button)

@spec decode_modifiers(integer()) :: MapSet.t(modifier())

Decodes modifier keys from a mouse event byte.

decode_urxvt_button(button)

@spec decode_urxvt_button(integer()) :: :left | :middle | :right | :release

Decodes URXVT button state from a mouse event byte.

disable(state)

@spec disable(mouse_state()) :: mouse_state()

Disables mouse tracking.

enable(state, mode)

@spec enable(mouse_state(), mouse_mode()) :: mouse_state()

Enables mouse tracking with the specified mode.

generate_report(state)

@spec generate_report(mouse_state()) :: String.t()

Generates a mouse event report based on the current state.

new()

@spec new() :: mouse_state()

Creates a new mouse state with default values.

parse_coordinates(rest)

@spec parse_coordinates(binary()) :: {:ok, {integer(), integer()}} | :error

Parses coordinates from a mouse event string.

parse_mouse_event(arg)

@spec parse_mouse_event(binary()) ::
  {:ok,
   %{
     type: :mouse,
     button: atom(),
     modifiers: MapSet.t(),
     position: {integer(), integer()},
     mode: :sgr
   }}
  | :error

Parses a mouse event in the format: <button>;<x>;<y>M

parse_sgr_pixels_event(arg)

@spec parse_sgr_pixels_event(binary()) ::
  {:ok,
   %{
     type: :mouse,
     button: atom(),
     modifiers: MapSet.t(),
     position: {integer(), integer()},
     mode: :sgr_pixels
   }}
  | :error

Parses an SGR pixels mouse event in the format: <button>;<x>;<y>M

parse_urxvt_event(arg)

@spec parse_urxvt_event(binary()) ::
  {:ok,
   %{
     type: :mouse,
     button: atom(),
     modifiers: MapSet.t(),
     position: {integer(), integer()},
     mode: :urxvt
   }}
  | :error

Parses a URXVT mouse event in the format: <button>;<x>;<y>M

process_event(state, arg)

@spec process_event(mouse_state(), binary()) :: {mouse_state(), map()}

Processes a mouse event and returns the updated state and event data. Supports extended mouse reporting modes including SGR pixels and URXVT.

update_button_state(state, button_state)

@spec update_button_state(
  mouse_state(),
  :none | :left | :middle | :right | :release
) :: mouse_state()

Updates the button state.

update_drag_state(state, drag_state)

@spec update_drag_state(mouse_state(), :none | :dragging | :drag_end) :: mouse_state()

Updates the drag state.

update_modifiers(state, modifiers)

@spec update_modifiers(mouse_state(), MapSet.t()) :: mouse_state()

Updates the modifiers state.

update_position(state, position)

@spec update_position(
  mouse_state(),
  {integer(), integer()}
) :: mouse_state()

Updates the mouse position.

update_state(state, event)

@spec update_state(mouse_state(), map()) :: mouse_state()

Updates the mouse state with new event data.