TermUI.Event (TermUI v0.2.0)

View Source

Event type definitions for TermUI.

Events represent user input from the terminal: keyboard presses, mouse actions, and focus changes. Events are routed to components by the EventRouter based on focus state and position.

Event Types

  • Key - Keyboard input (key press, char input)
  • Mouse - Mouse actions (click, move, scroll)
  • Focus - Focus changes (gained, lost)
  • Custom - Application-defined events

Examples

# Key event
event = Event.key(:enter)
event = Event.key(:a, char: "a")
event = Event.key(:c, modifiers: [:ctrl])

# Mouse event
event = Event.mouse(:click, :left, 10, 20)
event = Event.mouse(:move, nil, 15, 25)

# Focus event
event = Event.focus(:gained)
event = Event.focus(:lost)

Summary

Types

t()

Union type for all event types

Functions

Returns true if event is a custom event

Creates a focus event.

Returns true if event is a focus event

Checks if a modifier is present in the event.

Creates a key event.

Returns true if event is a key event

Returns true if event is a mouse event

Creates a paste event.

Returns true if event is a paste event

Creates a resize event.

Returns true if event is a resize event

Creates a tick event.

Returns true if event is a tick event

Returns the event type as an atom.

Types

t()

@type t() ::
  Key.t()
  | Mouse.t()
  | Focus.t()
  | Custom.t()
  | Resize.t()
  | Paste.t()
  | Tick.t()

Union type for all event types

Functions

custom(name, payload \\ nil, opts \\ [])

@spec custom(atom(), term(), keyword()) :: TermUI.Event.Custom.t()

Creates a custom event.

Examples

Event.custom(:submit, %{value: "hello"})

custom?(arg1)

@spec custom?(term()) :: boolean()

Returns true if event is a custom event

focus(action, opts \\ [])

Creates a focus event.

Examples

Event.focus(:gained)
Event.focus(:lost)

focus?(arg1)

@spec focus?(term()) :: boolean()

Returns true if event is a focus event

has_modifier?(map, modifier)

@spec has_modifier?(TermUI.Event.Key.t() | TermUI.Event.Mouse.t(), atom()) ::
  boolean()

Checks if a modifier is present in the event.

key(key, opts \\ [])

@spec key(
  atom(),
  keyword()
) :: TermUI.Event.Key.t()

Creates a key event.

Examples

Event.key(:enter)
Event.key(:a, char: "a")
Event.key(:c, modifiers: [:ctrl])

key?(arg1)

@spec key?(term()) :: boolean()

Returns true if event is a key event

mouse(action, button, x, y, opts \\ [])

Creates a mouse event.

Examples

Event.mouse(:click, :left, 10, 20)
Event.mouse(:move, nil, x, y)

mouse?(arg1)

@spec mouse?(term()) :: boolean()

Returns true if event is a mouse event

paste(content, opts \\ [])

@spec paste(
  String.t(),
  keyword()
) :: TermUI.Event.Paste.t()

Creates a paste event.

Examples

Event.paste("Hello, World!")

paste?(arg1)

@spec paste?(term()) :: boolean()

Returns true if event is a paste event

resize(width, height, opts \\ [])

Creates a resize event.

Examples

Event.resize(120, 40)

resize?(arg1)

@spec resize?(term()) :: boolean()

Returns true if event is a resize event

tick(interval, opts \\ [])

@spec tick(
  pos_integer(),
  keyword()
) :: TermUI.Event.Tick.t()

Creates a tick event.

Examples

Event.tick(16)  # ~60 FPS
Event.tick(1000)  # 1 second

tick?(arg1)

@spec tick?(term()) :: boolean()

Returns true if event is a tick event

type(arg1)

@spec type(
  TermUI.Event.Key.t()
  | TermUI.Event.Mouse.t()
  | TermUI.Event.Focus.t()
  | TermUI.Event.Custom.t()
  | TermUI.Event.Resize.t()
  | TermUI.Event.Paste.t()
  | TermUI.Event.Tick.t()
) :: :key | :mouse | :focus | :custom | :resize | :paste | :tick

Returns the event type as an atom.