Raxol.Terminal.Session (Raxol v2.0.1)
View SourceTerminal session module.
This module manages terminal sessions with pure functional patterns.
REFACTORED: All try/rescue blocks replaced with functional error handling.
Features:
- 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.
Stops a terminal session.
Updates the configuration of a terminal session.
Types
@type t() :: %Raxol.Terminal.Session{ auto_save: boolean(), emulator: Raxol.Terminal.Emulator.Struct.t(), height: non_neg_integer() | nil, id: String.t(), renderer: Raxol.Terminal.Renderer.t(), theme: map() | nil, title: String.t() | nil, width: non_neg_integer() | nil }
Functions
@spec count_active_sessions() :: non_neg_integer()
@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
Lists all saved sessions.
Loads a session from persistent storage.
@spec save_session(GenServer.server()) :: :ok
Saves the current session state to persistent storage.
@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"
@spec set_auto_save(GenServer.server(), boolean()) :: :ok
Sets whether the session should be automatically saved.
@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
@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