Raxol.Terminal.Cursor.Manager (Raxol v0.2.0)
View SourceTerminal cursor manager module.
This module handles the management of terminal cursors, including:
- Multiple cursor styles
- State persistence
- Animation system
- Position tracking
Summary
Functions
Adds the current cursor state to history.
Moves the cursor down by the specified number of rows.
Moves the cursor left by the specified number of columns.
Moves the cursor right by the specified number of columns.
Moves the cursor to a new position.
Moves the cursor to a specific column while maintaining the current row.
Moves the cursor up by the specified number of rows.
Creates a new cursor manager.
Restores the cursor state from history.
Restores the saved cursor position.
Saves the current cursor position.
Sets a custom cursor shape.
Sets the cursor state.
Sets the cursor style.
Updates the cursor blink state.
Types
@type cursor_shape() :: {non_neg_integer(), non_neg_integer()}
@type cursor_state() :: :visible | :hidden | :blinking
@type cursor_style() :: :block | :underline | :bar | :custom
@type t() :: %Raxol.Terminal.Cursor.Manager{ blink_rate: non_neg_integer(), custom_shape: String.t() | nil, history: [map()], history_index: non_neg_integer(), history_limit: non_neg_integer(), last_blink: integer(), position: {non_neg_integer(), non_neg_integer()}, saved_position: {non_neg_integer(), non_neg_integer()} | nil, shape: cursor_shape(), state: cursor_state(), style: cursor_style() }
Functions
Adds the current cursor state to history.
Examples
iex> alias Raxol.Terminal.Cursor.Manager
iex> cursor = Raxol.Terminal.Cursor.Manager.new()
iex> cursor = Raxol.Terminal.Cursor.Manager.add_to_history(cursor)
iex> length(cursor.history)
1
Moves the cursor down by the specified number of rows.
Examples
iex> alias Raxol.Terminal.Cursor.Manager
iex> cursor = Raxol.Terminal.Cursor.Manager.new()
iex> cursor = Raxol.Terminal.Cursor.Manager.move_down(cursor, 3)
iex> cursor.position
{0, 3}
Moves the cursor left by the specified number of columns.
Examples
iex> alias Raxol.Terminal.Cursor.Manager
iex> cursor = Raxol.Terminal.Cursor.Manager.new()
iex> cursor = Raxol.Terminal.Cursor.Manager.move_to(cursor, 5, 0)
iex> cursor = Raxol.Terminal.Cursor.Manager.move_left(cursor, 3)
iex> cursor.position
{2, 0}
Moves the cursor right by the specified number of columns.
Examples
iex> alias Raxol.Terminal.Cursor.Manager
iex> cursor = Raxol.Terminal.Cursor.Manager.new()
iex> cursor = Raxol.Terminal.Cursor.Manager.move_right(cursor, 3)
iex> cursor.position
{3, 0}
Moves the cursor to a new position.
Examples
iex> alias Raxol.Terminal.Cursor.Manager
iex> cursor = Raxol.Terminal.Cursor.Manager.new()
iex> cursor = Raxol.Terminal.Cursor.Manager.move_to(cursor, 10, 5)
iex> cursor.position
{10, 5}
Moves the cursor to a specific column while maintaining the current row.
Examples
iex> alias Raxol.Terminal.Cursor.Manager
iex> cursor = Raxol.Terminal.Cursor.Manager.new()
iex> cursor = Raxol.Terminal.Cursor.Manager.move_to(cursor, 0, 5)
iex> cursor = Raxol.Terminal.Cursor.Manager.move_to_col(cursor, 10)
iex> cursor.position
{10, 5}
Moves the cursor up by the specified number of rows.
Examples
iex> alias Raxol.Terminal.Cursor.Manager
iex> cursor = Raxol.Terminal.Cursor.Manager.new()
iex> cursor = Raxol.Terminal.Cursor.Manager.move_to(cursor, 5, 5)
iex> cursor = Raxol.Terminal.Cursor.Manager.move_up(cursor, 3)
iex> cursor.position
{5, 2}
Creates a new cursor manager.
Examples
iex> alias Raxol.Terminal.Cursor.Manager
iex> cursor = Raxol.Terminal.Cursor.Manager.new()
iex> cursor.position
{0, 0}
iex> cursor.style
:block
Restores the cursor state from history.
Examples
iex> alias Raxol.Terminal.Cursor.Manager
iex> cursor = Raxol.Terminal.Cursor.Manager.new()
iex> cursor = Raxol.Terminal.Cursor.Manager.add_to_history(cursor)
iex> cursor = Raxol.Terminal.Cursor.Manager.move_to(cursor, 10, 5)
iex> cursor = Raxol.Terminal.Cursor.Manager.restore_from_history(cursor)
iex> cursor.position
{0, 0}
Restores the saved cursor position.
Examples
iex> alias Raxol.Terminal.Cursor.Manager
iex> cursor = Raxol.Terminal.Cursor.Manager.new()
iex> cursor = Raxol.Terminal.Cursor.Manager.move_to(cursor, 10, 5)
iex> cursor = Raxol.Terminal.Cursor.Manager.save_position(cursor)
iex> cursor = Raxol.Terminal.Cursor.Manager.move_to(cursor, 0, 0)
iex> cursor = Raxol.Terminal.Cursor.Manager.restore_position(cursor)
iex> cursor.position
{10, 5}
Saves the current cursor position.
Examples
iex> alias Raxol.Terminal.Cursor.Manager
iex> cursor = Raxol.Terminal.Cursor.Manager.new()
iex> cursor = Raxol.Terminal.Cursor.Manager.move_to(cursor, 10, 5)
iex> cursor = Raxol.Terminal.Cursor.Manager.save_position(cursor)
iex> cursor.saved_position
{10, 5}
Sets a custom cursor shape.
Examples
iex> alias Raxol.Terminal.Cursor.Manager
iex> cursor = Raxol.Terminal.Cursor.Manager.new()
iex> cursor = Raxol.Terminal.Cursor.Manager.set_custom_shape(cursor, "█", {2, 1})
iex> cursor.style
:custom
iex> cursor.custom_shape
"█"
Sets the cursor state.
Examples
iex> alias Raxol.Terminal.Cursor.Manager
iex> cursor = Raxol.Terminal.Cursor.Manager.new()
iex> cursor = Raxol.Terminal.Cursor.Manager.set_state(cursor, :hidden)
iex> cursor.state
:hidden
Sets the cursor style.
Examples
iex> alias Raxol.Terminal.Cursor.Manager
iex> cursor = Raxol.Terminal.Cursor.Manager.new()
iex> cursor = Raxol.Terminal.Cursor.Manager.set_style(cursor, :underline)
iex> cursor.style
:underline
Updates the cursor blink state.
Examples
iex> alias Raxol.Terminal.Cursor.Manager
iex> cursor = Raxol.Terminal.Cursor.Manager.new()
iex> cursor = Raxol.Terminal.Cursor.Manager.set_state(cursor, :blinking)
iex> {cursor, visible} = Raxol.Terminal.Cursor.Manager.update_blink(cursor)
iex> is_boolean(visible)
true