Raxol.Terminal.Buffer.ConcurrentBuffer (Raxol v2.0.1)

View Source

A thread-safe buffer implementation using GenServer for concurrent access. Provides synchronous operations to ensure data integrity when multiple processes are reading/writing to the buffer simultaneously.

Summary

Functions

Performs a batch of operations atomically.

Performs a batch of operations from a list.

Returns a specification to start this module under a supervisor.

Clears the entire buffer.

Flushes any pending operations (for compatibility). Returns :ok immediately as operations are synchronous.

Gets the current buffer state for reading.

Gets a cell from the buffer.

Scrolls the buffer content.

Sets a cell in the buffer.

Starts a concurrent buffer server.

Stops the concurrent buffer server.

Writes text starting at the given position.

Functions

batch(server, fun)

@spec batch(pid() | atom(), (Raxol.Terminal.Buffer.t() -> Raxol.Terminal.Buffer.t())) ::
  :ok | {:error, term()}

Performs a batch of operations atomically.

batch_operations(server, operations)

@spec batch_operations(pid() | atom(), list()) :: :ok | {:error, term()}

Performs a batch of operations from a list.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

clear(server)

@spec clear(pid() | atom()) :: :ok

Clears the entire buffer.

fill_region(server, x, y, width, height, char, style \\ %{})

@spec fill_region(
  pid() | atom(),
  integer(),
  integer(),
  integer(),
  integer(),
  String.t(),
  map()
) :: :ok

Fills a region with a character.

flush(server)

@spec flush(pid() | atom()) :: :ok

Flushes any pending operations (for compatibility). Returns :ok immediately as operations are synchronous.

get_buffer(server)

@spec get_buffer(pid() | atom()) ::
  {:ok, Raxol.Terminal.Buffer.t()} | {:error, term()}

Gets the current buffer state for reading.

get_cell(server, x, y)

@spec get_cell(pid() | atom(), integer(), integer()) ::
  {:ok, Raxol.Terminal.Buffer.Cell.t()} | {:error, term()}

Gets a cell from the buffer.

handle_manager_cast(msg, state)

Callback implementation for Raxol.Core.Behaviours.BaseManager.handle_manager_cast/2.

handle_manager_info(msg, state)

Callback implementation for Raxol.Core.Behaviours.BaseManager.handle_manager_info/2.

scroll(server, lines)

@spec scroll(pid() | atom(), integer()) :: :ok

Scrolls the buffer content.

set_cell(server, x, y, cell)

@spec set_cell(pid() | atom(), integer(), integer(), Raxol.Terminal.Buffer.Cell.t()) ::
  :ok | {:error, term()}

Sets a cell in the buffer.

start_link(init_opts \\ [])

start_server(opts \\ [])

@spec start_server(keyword()) :: {:ok, pid()} | {:error, term()}

Starts a concurrent buffer server.

Options:

  • :width - Buffer width (default: 80)
  • :height - Buffer height (default: 24)
  • :name - GenServer name (optional)

stop(server)

@spec stop(pid() | atom()) :: :ok

Stops the concurrent buffer server.

write(server, x, y, text, style \\ %{})

@spec write(pid() | atom(), integer(), integer(), String.t(), map()) ::
  :ok | {:error, term()}

Writes text starting at the given position.