Raxol.Terminal.Buffer.Cursor (Raxol v0.5.0)
View SourceManages cursor state and operations for the screen buffer. This module handles cursor position, visibility, style, and blink state.
Summary
Functions
Checks if the cursor is blinking.
Gets the cursor position as a tuple of {row, col}.
Gets the current cursor position.
Gets the current cursor style.
Initializes a new cursor state with default values.
Moves the cursor backward by the specified number of columns.
Moves the cursor down by the specified number of lines.
Moves the cursor forward by the specified number of columns.
Moves the cursor to the specified position.
Moves the cursor up by the specified number of lines.
Sets the cursor blink state.
Sets the cursor position.
Sets the cursor position.
Sets the cursor style.
Sets the cursor visibility.
Checks if the cursor is visible.
Types
@type t() :: %Raxol.Terminal.Buffer.Cursor{ blink_state: boolean(), position: {non_neg_integer(), non_neg_integer()}, style: atom(), visible: boolean() }
Functions
@spec blinking?(Raxol.Terminal.ScreenBuffer.t()) :: boolean()
@spec blinking?(t()) :: boolean()
Checks if the cursor is blinking.
Parameters
cursor
- The cursor to query
Returns
A boolean indicating if the cursor is blinking.
Examples
iex> cursor = Cursor.init()
iex> Cursor.blinking?(cursor)
true
@spec get_cursor_position(t()) :: {non_neg_integer(), non_neg_integer()}
Gets the cursor position as a tuple of {row, col}.
Parameters
cursor
- The cursor to query
Returns
A tuple {row, col} representing the cursor position.
Examples
iex> cursor = Cursor.init()
iex> Cursor.get_cursor_position(cursor)
{0, 0}
@spec get_position(Raxol.Terminal.ScreenBuffer.t()) :: {non_neg_integer(), non_neg_integer()}
Gets the current cursor position.
Parameters
buffer
- The screen buffer to query
Returns
A tuple {x, y} representing the cursor position.
Examples
iex> buffer = ScreenBuffer.new(80, 24)
iex> Cursor.get_position(buffer)
{0, 0}
@spec get_style(Raxol.Terminal.ScreenBuffer.t()) :: atom()
Gets the current cursor style.
Parameters
buffer
- The screen buffer to query
Returns
The current cursor style.
Examples
iex> buffer = ScreenBuffer.new(80, 24)
iex> Cursor.get_style(buffer)
:block
@spec init() :: t()
Initializes a new cursor state with default values.
@spec move_backward(Raxol.Terminal.ScreenBuffer.t(), non_neg_integer()) :: Raxol.Terminal.ScreenBuffer.t()
Moves the cursor backward by the specified number of columns.
Parameters
buffer
- The screen buffer to modifycolumns
- Number of columns to move backward
Returns
The updated screen buffer with new cursor position.
Examples
iex> buffer = ScreenBuffer.new(80, 24)
iex> buffer = Cursor.move_backward(buffer, 2)
iex> Cursor.get_position(buffer)
{0, 0} # Cursor stays at left edge
@spec move_down(Raxol.Terminal.ScreenBuffer.t(), non_neg_integer()) :: Raxol.Terminal.ScreenBuffer.t()
Moves the cursor down by the specified number of lines.
Parameters
buffer
- The screen buffer to modifylines
- Number of lines to move down
Returns
The updated screen buffer with new cursor position.
Examples
iex> buffer = ScreenBuffer.new(80, 24)
iex> buffer = Cursor.move_down(buffer, 2)
iex> Cursor.get_position(buffer)
{0, 2}
@spec move_forward(Raxol.Terminal.ScreenBuffer.t(), non_neg_integer()) :: Raxol.Terminal.ScreenBuffer.t()
Moves the cursor forward by the specified number of columns.
Parameters
buffer
- The screen buffer to modifycolumns
- Number of columns to move forward
Returns
The updated screen buffer with new cursor position.
Examples
iex> buffer = ScreenBuffer.new(80, 24)
iex> buffer = Cursor.move_forward(buffer, 2)
iex> Cursor.get_position(buffer)
{2, 0}
@spec move_to( Raxol.Terminal.ScreenBuffer.t(), {non_neg_integer(), non_neg_integer()} ) :: Raxol.Terminal.ScreenBuffer.t()
Moves the cursor to the specified position.
Parameters
buffer
- The screen buffer to modifyposition
- The target position as {x, y}
Returns
The updated screen buffer with new cursor position.
Examples
iex> buffer = ScreenBuffer.new(80, 24)
iex> buffer = Cursor.move_to(buffer, {10, 5})
iex> Cursor.get_position(buffer)
{10, 5}
@spec move_up(Raxol.Terminal.ScreenBuffer.t(), non_neg_integer()) :: Raxol.Terminal.ScreenBuffer.t()
Moves the cursor up by the specified number of lines.
Parameters
buffer
- The screen buffer to modifylines
- Number of lines to move up
Returns
The updated screen buffer with new cursor position.
Examples
iex> buffer = ScreenBuffer.new(80, 24)
iex> buffer = Cursor.move_up(buffer, 2)
iex> Cursor.get_position(buffer)
{0, 0} # Cursor stays at top
@spec set_blink(Raxol.Terminal.ScreenBuffer.t(), boolean()) :: Raxol.Terminal.ScreenBuffer.t()
Sets the cursor blink state.
Parameters
buffer
- The screen buffer to modifyblink
- Whether the cursor should blink
Returns
The updated screen buffer with new cursor blink state.
Examples
iex> buffer = ScreenBuffer.new(80, 24)
iex> buffer = Cursor.set_blink(buffer, false)
iex> Cursor.blinking?(buffer)
false
@spec set_cursor_position(t(), non_neg_integer(), non_neg_integer()) :: t()
Sets the cursor position.
Parameters
cursor
- The cursor to modifyrow
- The row positioncol
- The column position
Returns
The updated cursor with new position.
Examples
iex> cursor = Cursor.init()
iex> cursor = Cursor.set_cursor_position(cursor, 5, 10)
iex> Cursor.get_cursor_position(cursor)
{5, 10}
@spec set_position( Raxol.Terminal.ScreenBuffer.t(), non_neg_integer(), non_neg_integer() ) :: Raxol.Terminal.ScreenBuffer.t()
Sets the cursor position.
Parameters
buffer
- The screen buffer to modifyx
- The x-coordinate (column)y
- The y-coordinate (row)
Returns
The updated screen buffer with new cursor position.
Examples
iex> buffer = ScreenBuffer.new(80, 24)
iex> buffer = Cursor.set_position(buffer, 10, 5)
iex> Cursor.get_position(buffer)
{10, 5}
@spec set_style(Raxol.Terminal.ScreenBuffer.t(), atom()) :: Raxol.Terminal.ScreenBuffer.t()
Sets the cursor style.
Parameters
buffer
- The screen buffer to modifystyle
- The cursor style (:block, :underline, :bar)
Returns
The updated screen buffer with new cursor style.
Examples
iex> buffer = ScreenBuffer.new(80, 24)
iex> buffer = Cursor.set_style(buffer, :underline)
iex> Cursor.get_style(buffer)
:underline
@spec set_visibility(Raxol.Terminal.ScreenBuffer.t(), boolean()) :: Raxol.Terminal.ScreenBuffer.t()
Sets the cursor visibility.
Parameters
buffer
- The screen buffer to modifyvisible
- Whether the cursor should be visible
Returns
The updated screen buffer with new cursor visibility.
Examples
iex> buffer = ScreenBuffer.new(80, 24)
iex> buffer = Cursor.set_visibility(buffer, false)
iex> Cursor.visible?(buffer)
false
@spec visible?(Raxol.Terminal.ScreenBuffer.t()) :: boolean()
@spec visible?(t()) :: boolean()
Checks if the cursor is visible.
Parameters
cursor
- The cursor to query
Returns
A boolean indicating cursor visibility.
Examples
iex> cursor = Cursor.init()
iex> Cursor.visible?(cursor)
true