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

View Source

A state machine for parsing ANSI escape sequences. This module provides a more efficient alternative to regex-based parsing.

Summary

Functions

Creates a new parser state with default values.

Processes input bytes through the state machine. Returns the updated state and any parsed sequences.

Types

parser_state()

@type parser_state() :: %{
  state: state(),
  params_buffer: String.t(),
  intermediates_buffer: String.t(),
  payload_buffer: String.t(),
  final_byte: String.t() | nil,
  designating_gset: atom() | nil
}

sequence()

@type sequence() :: %{
  type: sequence_type(),
  command: String.t(),
  params: [String.t()],
  intermediate: String.t(),
  final: String.t(),
  text: String.t()
}

sequence_type()

@type sequence_type() :: :csi | :osc | :sos | :pm | :apc | :esc | :text

state()

@type state() ::
  :ground
  | :escape
  | :csi_entry
  | :csi_param
  | :csi_intermediate
  | :csi_final
  | :osc_string
  | :osc_string_maybe_st
  | :dcs_entry
  | :dcs_passthrough
  | :dcs_passthrough_maybe_st
  | :designate_charset

Functions

new()

@spec new() :: parser_state()

Creates a new parser state with default values.

process(state, input)

@spec process(parser_state(), binary()) :: {parser_state(), [sequence()]}

Processes input bytes through the state machine. Returns the updated state and any parsed sequences.