Raxol.Terminal.Output.Manager (Raxol v2.0.1)

View Source

Manages terminal output buffering, event processing, styling, and formatting. This module handles output events, applies styles and formatting rules, and tracks metrics.

Summary

Functions

Adds a custom formatting rule. Returns the updated manager.

Adds a custom style to the style map. Returns the updated manager.

Flushes the output buffer. Returns the updated manager with an empty buffer.

Gets the current metrics.

Creates a new output manager instance.

Processes a batch of output events. Returns {:ok, updated_manager} or {:error, :invalid_event}.

Processes a single output event. Returns {:ok, updated_manager} or {:error, :invalid_event}.

Types

buffer()

@type buffer() :: %{events: [event()], max_size: non_neg_integer()}

event()

@type event() :: %{
  content: String.t(),
  style: String.t(),
  timestamp: integer(),
  priority: integer()
}

format_rule()

@type format_rule() :: (String.t() -> String.t())

metrics()

@type metrics() :: %{
  processed_events: non_neg_integer(),
  batch_count: non_neg_integer(),
  format_applications: non_neg_integer(),
  style_applications: non_neg_integer()
}

style()

@type style() :: %{
  foreground: String.t() | nil,
  background: String.t() | nil,
  bold: boolean(),
  italic: boolean(),
  underline: boolean()
}

t()

@type t() :: %Raxol.Terminal.Output.Manager{
  batch_size: pos_integer(),
  buffer: buffer(),
  format_rules: [format_rule()],
  metrics: metrics(),
  style_map: %{required(String.t()) => style()}
}

Functions

add_format_rule(manager, rule)

@spec add_format_rule(t(), format_rule()) :: t()

Adds a custom formatting rule. Returns the updated manager.

add_style(manager, style_name, style)

@spec add_style(t(), String.t(), style()) :: t()

Adds a custom style to the style map. Returns the updated manager.

flush_buffer(manager)

@spec flush_buffer(t()) :: t()

Flushes the output buffer. Returns the updated manager with an empty buffer.

get_metrics(manager)

@spec get_metrics(t()) :: metrics()

Gets the current metrics.

new(opts \\ [])

@spec new(keyword()) :: t()

Creates a new output manager instance.

process_batch(manager, events)

@spec process_batch(t(), [event()]) :: {:ok, t()} | {:error, :invalid_event}

Processes a batch of output events. Returns {:ok, updated_manager} or {:error, :invalid_event}.

process_output(manager, event)

@spec process_output(t(), event()) :: {:ok, t()} | {:error, :invalid_event}

Processes a single output event. Returns {:ok, updated_manager} or {:error, :invalid_event}.