Raxol.Terminal.Buffer.Cursor (Raxol v0.5.0)

View Source

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

t()

@type t() :: %Raxol.Terminal.Buffer.Cursor{
  blink_state: boolean(),
  position: {non_neg_integer(), non_neg_integer()},
  style: atom(),
  visible: boolean()
}

Functions

blinking?(buffer)

@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

get_cursor_position(cursor)

@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}

get_position(buffer)

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}

get_style(buffer)

@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

init()

@spec init() :: t()

Initializes a new cursor state with default values.

move_backward(buffer, columns)

Moves the cursor backward by the specified number of columns.

Parameters

  • buffer - The screen buffer to modify
  • columns - 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

move_down(buffer, lines)

Moves the cursor down by the specified number of lines.

Parameters

  • buffer - The screen buffer to modify
  • lines - 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}

move_forward(buffer, columns)

Moves the cursor forward by the specified number of columns.

Parameters

  • buffer - The screen buffer to modify
  • columns - 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}

move_to(buffer, arg)

Moves the cursor to the specified position.

Parameters

  • buffer - The screen buffer to modify
  • position - 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}

move_up(buffer, lines)

Moves the cursor up by the specified number of lines.

Parameters

  • buffer - The screen buffer to modify
  • lines - 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

set_blink(buffer, blink)

Sets the cursor blink state.

Parameters

  • buffer - The screen buffer to modify
  • blink - 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

set_cursor_position(cursor, row, col)

@spec set_cursor_position(t(), non_neg_integer(), non_neg_integer()) :: t()

Sets the cursor position.

Parameters

  • cursor - The cursor to modify
  • row - The row position
  • col - 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}

set_position(buffer, x, y)

Sets the cursor position.

Parameters

  • buffer - The screen buffer to modify
  • x - 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}

set_style(buffer, style)

Sets the cursor style.

Parameters

  • buffer - The screen buffer to modify
  • style - 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

set_visibility(buffer, visible)

Sets the cursor visibility.

Parameters

  • buffer - The screen buffer to modify
  • visible - 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

visible?(buffer)

@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