gsh/input/terminal

The terminal module handles low-level standard output and ANSI escape sequences.

Because the REPL operates in terminal raw mode, standard formatting rules (like a simple \n moving the cursor down and to the left) no longer apply. This module provides a clean API for rendering text and manually manipulating the 2D position of the cursor on the screen without leaking escape codes into the rest of the application.

Values

pub fn clear_below() -> Nil

Clears all terminal text from the current cursor position down to the bottom of the screen. Used by the editor to wipe old multiline blocks before redrawing.

pub fn clear_line() -> Nil

Clears the entire current line and returns the cursor to the leftmost column. Uses the ANSI sequence [2K (clear entire line) and \r (carriage return).

pub fn clear_screen() -> Nil

Clears the entire terminal screen and resets the cursor to the top-left (0,0) position.

pub fn cursor_down(count: Int) -> Nil

Moves the terminal cursor straight down by the specified number of rows.

pub fn cursor_left(count: Int) -> Nil

Moves the terminal cursor to the left by the specified number of columns.

pub fn cursor_right(count: Int) -> Nil

Moves the terminal cursor to the right by the specified number of columns.

pub fn cursor_up(count: Int) -> Nil

Moves the terminal cursor straight up by the specified number of rows.

pub fn hide_cursor() -> Nil

Hides the hardware terminal cursor. Useful when redrawing large multiline buffers to prevent visual flickering.

pub fn move_start() -> Nil

Snaps the cursor directly to the first column of the current line.

pub fn print(text: String) -> Nil

Prints text to the screen. In raw mode, a standard newline (\n) only moves the cursor down, not to the start of the next line. This safely replaces all newlines with CRLF (\r\n) so text renders normally.

pub fn println(text: String) -> Nil

Prints text to the screen and appends a CRLF (\r\n) to jump to the next line.

pub fn show_cursor() -> Nil

Restores the hardware terminal cursor to visible.

Search Document