Raxol.Terminal.EmulatorBehaviour behaviour (Raxol v0.4.0)

View Source

Defines the behaviour for the core Terminal Emulator.

This contract outlines the essential functions for managing terminal state, processing input, and handling resizing.

Summary

Callbacks

Returns the currently active screen buffer.

Gets the current cursor position (0-based).

Gets the current cursor visibility state.

Creates a new emulator with default dimensions and options.

Creates a new emulator with specified dimensions and default options.

Creates a new emulator with specified dimensions and options.

Creates a new emulator with specified dimensions, session ID, and client options.

Processes input data (e.g., user typing, escape sequences).

Resizes the emulator's screen buffers.

Updates the currently active screen buffer in the emulator state.

Types

t()

@type t() :: %{
  __struct__: module(),
  main_screen_buffer: Raxol.Terminal.ScreenBuffer.t(),
  alternate_screen_buffer: Raxol.Terminal.ScreenBuffer.t(),
  active_buffer_type: :main | :alternate,
  cursor: Raxol.Terminal.Cursor.Manager.t(),
  scroll_region: {non_neg_integer(), non_neg_integer()} | nil,
  style: Raxol.Terminal.ANSI.TextFormatting.text_style(),
  memory_limit: non_neg_integer(),
  charset_state: Raxol.Terminal.ANSI.CharacterSets.charset_state(),
  mode_manager: Raxol.Terminal.ModeManager.t(),
  plugin_manager: Raxol.Plugins.Manager.Core.t(),
  options: map(),
  current_hyperlink_url: String.t() | nil,
  window_title: String.t() | nil,
  icon_name: String.t() | nil,
  tab_stops: MapSet.t(),
  output_buffer: String.t(),
  cursor_style: atom(),
  parser_state: map(),
  command_history: list(),
  max_command_history: non_neg_integer(),
  current_command_buffer: String.t(),
  saved_cursor: {non_neg_integer(), non_neg_integer()},
  state_stack: any(),
  last_col_exceeded: boolean()
}

Callbacks

get_active_buffer(emulator)

@callback get_active_buffer(emulator :: t()) :: Raxol.Terminal.ScreenBuffer.t()

Returns the currently active screen buffer.

get_cursor_position(emulator)

@callback get_cursor_position(emulator :: t()) :: {non_neg_integer(), non_neg_integer()}

Gets the current cursor position (0-based).

get_cursor_visible(emulator)

@callback get_cursor_visible(emulator :: t()) :: boolean()

Gets the current cursor visibility state.

new()

@callback new() :: t()

Creates a new emulator with default dimensions and options.

new(width, height)

@callback new(width :: non_neg_integer(), height :: non_neg_integer()) :: t()

Creates a new emulator with specified dimensions and default options.

new(width, height, opts)

@callback new(
  width :: non_neg_integer(),
  height :: non_neg_integer(),
  opts :: keyword()
) :: t()

Creates a new emulator with specified dimensions and options.

new(width, height, session_id, client_options)

@callback new(
  width :: non_neg_integer(),
  height :: non_neg_integer(),
  session_id :: any(),
  client_options :: map()
) :: {:ok, t()} | {:error, any()}

Creates a new emulator with specified dimensions, session ID, and client options.

process_input(emulator, input)

@callback process_input(emulator :: t(), input :: String.t()) :: {t(), String.t()}

Processes input data (e.g., user typing, escape sequences).

resize(emulator, new_width, new_height)

@callback resize(
  emulator :: t(),
  new_width :: non_neg_integer(),
  new_height :: non_neg_integer()
) :: t()

Resizes the emulator's screen buffers.

update_active_buffer(emulator, new_buffer)

@callback update_active_buffer(
  emulator :: t(),
  new_buffer :: Raxol.Terminal.ScreenBuffer.t()
) :: t()

Updates the currently active screen buffer in the emulator state.