Raxol.Terminal.Session (Raxol v0.5.0)

View Source

Terminal session module.

This module manages terminal sessions, including:

  • Session lifecycle
  • Input/output handling
  • State management
  • Configuration
  • Session persistence and recovery

Summary

Functions

Gets the current state of a terminal session.

Lists all saved sessions.

Loads a session from persistent storage.

Saves the current session state to persistent storage.

Sends input to a terminal session.

Sets whether the session should be automatically saved.

Starts a new terminal session.

Stops a terminal session.

Updates the configuration of a terminal session.

Types

t()

@type t() :: %Raxol.Terminal.Session{
  auto_save: boolean(),
  emulator: Raxol.Terminal.Emulator.Struct.t(),
  height: non_neg_integer(),
  id: String.t(),
  renderer: Raxol.Terminal.Renderer.t(),
  theme: map(),
  title: String.t(),
  width: non_neg_integer()
}

Functions

count_active_sessions()

@spec count_active_sessions() :: non_neg_integer()

get_state(pid)

@spec get_state(GenServer.server()) :: t()

Gets the current state of a terminal session.

Examples

iex> {:ok, pid} = Session.start_link()
iex> state = Session.get_state(pid)
iex> state.width
80

list_saved_sessions()

@spec list_saved_sessions() :: {:ok, [String.t()]} | {:error, term()}

Lists all saved sessions.

load_session(session_id)

@spec load_session(String.t()) :: {:ok, pid()} | {:error, term()}

Loads a session from persistent storage.

save_session(pid)

@spec save_session(GenServer.server()) :: :ok | {:error, term()}

Saves the current session state to persistent storage.

send_input(pid, input)

@spec send_input(GenServer.server(), String.t()) :: :ok

Sends input to a terminal session.

Examples

iex> {:ok, pid} = Session.start_link()
iex> :ok = Session.send_input(pid, "test")
iex> state = Session.get_state(pid)
iex> state.input.buffer
"test"

set_auto_save(pid, enabled)

@spec set_auto_save(GenServer.server(), boolean()) :: :ok

Sets whether the session should be automatically saved.

start_link(opts \\ [])

@spec start_link(keyword()) :: GenServer.on_start()

Starts a new terminal session.

Examples

iex> {:ok, pid} = Session.start_link(%{width: 80, height: 24})
iex> Process.alive?(pid)
true

stop(pid)

@spec stop(GenServer.server()) :: :ok

Stops a terminal session.

Examples

iex> {:ok, pid} = Session.start_link()
iex> :ok = Session.stop(pid)
iex> Process.alive?(pid)
false

update_config(pid, config)

@spec update_config(GenServer.server(), map()) :: :ok

Updates the configuration of a terminal session.

Examples

iex> {:ok, pid} = Session.start_link()
iex> :ok = Session.update_config(pid, %{width: 100, height: 30})
iex> state = Session.get_state(pid)
iex> state.width
100