Raxol.Terminal.Cursor.Manager (Raxol v0.2.0)

View Source

Terminal 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

cursor_shape()

@type cursor_shape() :: {non_neg_integer(), non_neg_integer()}

cursor_state()

@type cursor_state() :: :visible | :hidden | :blinking

cursor_style()

@type cursor_style() :: :block | :underline | :bar | :custom

t()

@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

add_to_history(cursor)

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

move_down(cursor, count)

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}

move_left(cursor, count)

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}

move_right(cursor, count)

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}

move_to(cursor, x, y)

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}

move_to_col(cursor, col)

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}

move_up(cursor, count)

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}

new()

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

restore_from_history(cursor)

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}

restore_position(cursor)

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}

save_position(cursor)

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}

set_custom_shape(cursor, shape, dimensions)

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
"█"

set_state(cursor, state)

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

set_style(cursor, style)

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

update_blink(cursor)

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