Raxol.Terminal.Emulator (Raxol v0.2.0)
View SourceManages the state of the terminal emulator, including screen buffer, cursor position, attributes, and modes.
Summary
Functions
Gets the currently active screen buffer.
Gets the current cursor position from the emulator.
Gets whether the cursor is currently visible.
Creates a new terminal emulator instance with the specified dimensions and options.
Processes input from the user, handling both regular characters and escape sequences. Processes the entire input string recursively.
Resizes the emulator's screen buffers.
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.charset_state(), current_hyperlink_url: String.t() | nil, cursor: Raxol.Terminal.Cursor.Manager.t(), cursor_style: cursor_style_type(), icon_name: String.t() | nil, last_col_exceeded: term(), main_screen_buffer: Raxol.Terminal.ScreenBuffer.t(), memory_limit: non_neg_integer(), mode_state: Raxol.Terminal.ANSI.ScreenModes.screen_state(), options: map(), output_buffer: String.t(), plugin_manager: Raxol.Plugins.PluginManager.t(), saved_cursor: term(), scroll_region: {non_neg_integer(), non_neg_integer()} | nil, state_stack: term(), style: Raxol.Terminal.ANSI.TextFormatting.text_style(), tab_stops: MapSet.t(), window_title: String.t() | nil }
Functions
@spec get_active_buffer(t()) :: Raxol.Terminal.ScreenBuffer.t()
Gets the currently active screen buffer.
@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
@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}
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, "\e[1;31mRed\e[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 \e[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
@spec update_active_buffer( t(), Raxol.Terminal.ScreenBuffer.t() ) :: t()
Updates the currently active screen buffer.