Vtex.Output.Cursor (Vtex v0.1.0)

Copy Markdown View Source

Cursor-control output sequences.

Every function returns the bytes of a control sequence for you to write to the terminal; the library performs no IO of its own. Positions are 1-based, matching the terminal's own convention.

transport_write([Vtex.Output.Cursor.to(1, 1), Vtex.Output.Cursor.hide()])

Summary

Functions

Move the cursor to col on the current row (1-based).

Hide the cursor.

Move the cursor n cells in a direction (:up, :down, :left, :right).

Restore the cursor position saved by save/0 (DECRC).

Save the cursor position (DECSC). Pair with restore/0.

Show the cursor.

Move the cursor to row, col (both 1-based).

Functions

column(col)

@spec column(pos_integer()) :: binary()

Move the cursor to col on the current row (1-based).

Examples

iex> Vtex.Output.Cursor.column(1)
"\e[1G"

hide()

@spec hide() :: binary()

Hide the cursor.

Examples

iex> Vtex.Output.Cursor.hide()
"\e[?25l"

move(direction, n \\ 1)

@spec move(:up | :down | :left | :right, pos_integer()) :: binary()

Move the cursor n cells in a direction (:up, :down, :left, :right).

Examples

iex> Vtex.Output.Cursor.move(:up, 3)
"\e[3A"

iex> Vtex.Output.Cursor.move(:right)
"\e[1C"

restore()

@spec restore() :: binary()

Restore the cursor position saved by save/0 (DECRC).

Examples

iex> Vtex.Output.Cursor.restore()
"\e8"

save()

@spec save() :: binary()

Save the cursor position (DECSC). Pair with restore/0.

Examples

iex> Vtex.Output.Cursor.save()
"\e7"

show()

@spec show() :: binary()

Show the cursor.

Examples

iex> Vtex.Output.Cursor.show()
"\e[?25h"

to(row, col)

@spec to(pos_integer(), pos_integer()) :: binary()

Move the cursor to row, col (both 1-based).

Examples

iex> Vtex.Output.Cursor.to(5, 10)
"\e[5;10H"