Screen-control output sequences: clearing, the alternate buffer, scroll regions.
Every function returns the bytes of a control sequence for you to write to the terminal; the library performs no IO of its own.
The alternate screen buffer is what full-screen apps (editors, pagers) use so the user's scrollback is restored on exit:
transport_write(Vtex.Output.Screen.enter_alternate())
# ... draw the UI ...
transport_write(Vtex.Output.Screen.leave_alternate())
Summary
Functions
Clear the whole screen (does not move the cursor).
Clear from the start of the screen to the cursor.
Clear from the cursor to the end of the screen.
Clear the current line (does not move the cursor).
Clear from the cursor to the end of the line.
Clear from the start of the line to the cursor.
Switch to the alternate screen buffer (saving the primary screen).
Leave the alternate screen buffer, restoring the primary screen.
Reset the scroll region to the full screen.
Set the scroll region to rows top..bottom (1-based, inclusive).
Functions
@spec clear() :: binary()
Clear the whole screen (does not move the cursor).
Examples
iex> Vtex.Output.Screen.clear()
"\e[2J"
@spec clear_above() :: binary()
Clear from the start of the screen to the cursor.
Examples
iex> Vtex.Output.Screen.clear_above()
"\e[1J"
@spec clear_below() :: binary()
Clear from the cursor to the end of the screen.
Examples
iex> Vtex.Output.Screen.clear_below()
"\e[0J"
@spec clear_line() :: binary()
Clear the current line (does not move the cursor).
Examples
iex> Vtex.Output.Screen.clear_line()
"\e[2K"
@spec clear_line_end() :: binary()
Clear from the cursor to the end of the line.
Examples
iex> Vtex.Output.Screen.clear_line_end()
"\e[0K"
@spec clear_line_start() :: binary()
Clear from the start of the line to the cursor.
Examples
iex> Vtex.Output.Screen.clear_line_start()
"\e[1K"
@spec enter_alternate() :: binary()
Switch to the alternate screen buffer (saving the primary screen).
Examples
iex> Vtex.Output.Screen.enter_alternate()
"\e[?1049h"
@spec leave_alternate() :: binary()
Leave the alternate screen buffer, restoring the primary screen.
Examples
iex> Vtex.Output.Screen.leave_alternate()
"\e[?1049l"
@spec reset_scroll_region() :: binary()
Reset the scroll region to the full screen.
Examples
iex> Vtex.Output.Screen.reset_scroll_region()
"\e[r"
@spec scroll_region(pos_integer(), pos_integer()) :: binary()
Set the scroll region to rows top..bottom (1-based, inclusive).
Examples
iex> Vtex.Output.Screen.scroll_region(2, 23)
"\e[2;23r"