Manages 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 from the ScreenBuffer struct.
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 on the ScreenBuffer struct.
Sets the cursor position.
Sets the cursor style.
Sets the cursor visibility.
Checks if the cursor is visible.
Types
@type cursor_style() :: :block | :underline | :bar
@type t() :: %Raxol.Terminal.Buffer.Cursor{ blink_state: boolean(), position: {non_neg_integer(), non_neg_integer()}, style: cursor_style(), visible: boolean() }
Functions
Checks if the cursor is blinking.
Parameters
buffer- The screen buffer to query
Returns
A boolean indicating if the cursor is blinking.
Examples
iex> buffer = ScreenBuffer.new(80, 24)
iex> Cursor.blinking?(buffer)
true
Gets the cursor position from the ScreenBuffer struct.
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}
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
Initializes a new cursor state with default values.
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
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}
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}
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}
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
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
Sets the cursor position on the ScreenBuffer struct.
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}
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
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
Checks if the cursor is visible.
Parameters
buffer- The screen buffer to query
Returns
A boolean indicating cursor visibility.
Examples
iex> buffer = ScreenBuffer.new(80, 24)
iex> Cursor.visible?(buffer)
true