Raxol.Terminal.Emulator (Raxol v0.3.0)
View SourceManages the state of the terminal emulator, including screen buffer, cursor position, attributes, and modes.
Summary
Functions
Gets the currently active buffer (:main or :alt) from the emulator state.
Gets the current cursor position from the emulator.
Gets whether the cursor is currently visible.
Checks if the cursor is below the scroll region and scrolls up if necessary. Called after operations like LF, IND, NEL that might move the cursor off-screen. Version called with no specific target Y - checks current cursor position.
See Raxol.Terminal.Cursor.Manager.move_down/2
.
See Raxol.Terminal.Cursor.Manager.move_left/2
.
See Raxol.Terminal.Cursor.Manager.move_right/2
.
See Raxol.Terminal.Cursor.Manager.move_to_column/2
.
See Raxol.Terminal.Cursor.Manager.move_up/2
.
Creates a new terminal emulator instance with the specified dimensions and options.
Creates a new terminal emulator instance with specified dimensions, session ID, and client options. This function is required by the TerminalChannel.
Processes input from the user, handling both regular characters and escape sequences. Processes the entire input string recursively.
Resizes the emulator's screen buffers.
See Raxol.Terminal.Cursor.Manager.set_position/2
.
Updates the currently active screen buffer.
Types
@type cursor_style_type() ::
:blinking_block
| :steady_block
| :blinking_underline
| :steady_underline
| :blinking_bar
| :steady_bar
@type t() :: %Raxol.Terminal.Emulator{ active_buffer_type: :main | :alternate, alternate_screen_buffer: Raxol.Terminal.ScreenBuffer.t(), charset_state: Raxol.Terminal.ANSI.CharacterSets.CharacterSets.charset_state(), command: Raxol.Terminal.Command.Manager.t(), command_history: list(), current_command_buffer: String.t(), current_hyperlink_url: String.t() | nil, cursor: Raxol.Terminal.Cursor.Manager.t(), cursor_style: cursor_style_type(), height: non_neg_integer(), icon_name: String.t() | nil, last_col_exceeded: term(), last_key_event: map() | nil, main_screen_buffer: Raxol.Terminal.ScreenBuffer.t(), max_command_history: non_neg_integer(), memory_limit: non_neg_integer(), mode_manager: Raxol.Terminal.ModeManager.t(), options: map(), output_buffer: String.t(), parser_state: Raxol.Terminal.Parser.State.t(), plugin_manager: Raxol.Plugins.PluginManager.t(), saved_cursor: term(), scroll_region: {non_neg_integer(), non_neg_integer()} | nil, state: Raxol.Terminal.State.Manager.t(), state_stack: term(), style: Raxol.Terminal.ANSI.TextFormatting.text_style(), tab_stops: MapSet.t(), width: non_neg_integer(), window_state: %{ title: String.t(), icon_name: String.t(), size: {non_neg_integer(), non_neg_integer()}, position: {non_neg_integer(), non_neg_integer()}, stacking_order: :normal | :maximized | :iconified, iconified: boolean(), maximized: boolean(), previous_size: {non_neg_integer(), non_neg_integer()} | nil }, window_title: String.t() | nil }
Functions
@spec get_active_buffer(t()) :: Raxol.Terminal.ScreenBuffer.t()
Gets the currently active buffer (:main or :alt) from the emulator state.
@spec get_cursor_position(t()) :: {non_neg_integer(), non_neg_integer()}
Gets the current cursor position from the emulator.
Parameters
emulator
- The emulator to get the cursor position from
Returns
A tuple {x, y} representing the cursor position
Gets whether the cursor is currently visible.
Parameters
emulator
- The emulator to check
Returns
Boolean indicating if cursor is visible
Checks if the cursor is below the scroll region and scrolls up if necessary. Called after operations like LF, IND, NEL that might move the cursor off-screen. Version called with no specific target Y - checks current cursor position.
See Raxol.Terminal.Cursor.Manager.move_down/2
.
See Raxol.Terminal.Cursor.Manager.move_left/2
.
See Raxol.Terminal.Cursor.Manager.move_right/2
.
See Raxol.Terminal.Cursor.Manager.move_to_column/2
.
See Raxol.Terminal.Cursor.Manager.move_up/2
.
@spec new(non_neg_integer(), non_neg_integer(), keyword()) :: t()
Creates a new terminal emulator instance with the specified dimensions and options.
Examples
iex> emulator = Raxol.Terminal.Emulator.new(80, 24, %{})
iex> emulator.width
80
iex> emulator.height
24
iex> emulator.cursor.position
{0, 0}
Creates a new terminal emulator instance with specified dimensions, session ID, and client options. This function is required by the TerminalChannel.
Processes input from the user, handling both regular characters and escape sequences. Processes the entire input string recursively.
Examples
iex> emulator = Raxol.Terminal.Emulator.new(80, 24, %{})
iex> {emulator, _} = Raxol.Terminal.Emulator.process_input(emulator, "a")
# Cursor position is now 1-based, so {1, 1} after 'a'
iex> emulator.cursor.position
{1, 1}
iex> emulator = Raxol.Terminal.Emulator.new()
iex> {emulator, _} = Raxol.Terminal.Emulator.process_input(emulator, "[1;31mRed[0m Text")
iex> {x, y} = emulator.cursor.position
iex> x # Length of "Red Text" (8 chars) + starting at 1 = 9
9
iex> emulator.style.foreground # Should be reset by [0m
nil
@spec resize( t(), non_neg_integer(), non_neg_integer() ) :: t()
Resizes the emulator's screen buffers.
Parameters
emulator
- The emulator to resizenew_width
- New width in columnsnew_height
- New height in rows
Returns
Updated emulator with resized buffers
See Raxol.Terminal.Cursor.Manager.set_position/2
.
@spec update_active_buffer( t(), Raxol.Terminal.ScreenBuffer.t() ) :: t()
Updates the currently active screen buffer.
See Raxol.Terminal.State.Manager.update_last_col_exceeded/2
.