etch/terminal

This module provides terminal associated functions like entering raw mode, alternative screen, setting title etc.

Types

Used in clear function.

pub type ClearType {
  All
  Purge
  FromCursorDown
  FromCursorUp
  CurrentLine
  UntilNewLine
}

Constructors

  • All

    Clears the whole screen.

  • Purge

    Clears the whole screen and the history.

  • FromCursorDown

    Clears cells from the cursor downwards.

  • FromCursorUp

    Clears cells from the cursor upwards.

  • CurrentLine

    Clears cells at the current cursor row.

  • UntilNewLine

    Clears cells from the cursor positon until the end.

Event error.

pub type TerminalError {
  FailedToEnterRawMode
  FailedToExitRawMode
  CouldNotGetWindowSize
}

Constructors

  • FailedToEnterRawMode
  • FailedToExitRawMode
  • CouldNotGetWindowSize

Values

pub fn clear(t: ClearType) -> String

Clears the terminal. See ClearType. It is prefered not to use this directly. See Clear.

pub fn disable_line_wrap() -> String

Disable line wrap. It is prefered not to use this directly. See DisableLineWrap.

pub fn enable_line_wrap() -> String

Enable line wrap. It is prefered not to use this directly. See EnableLineWrap.

pub fn enter_alternative() -> String

Enter alternative screen. It is prefered not to use this directly. See EnterAlternative.

pub fn enter_raw() -> Result(Nil, TerminalError)

Enters raw mode.

Raw mode is a mode where the terminal does not process input, but instead passes it directly to the application. This means that:

  • Input is not echoed to the screen
  • Input is not line-buffered (characters are available immediately)
  • Some special characters are not processed by the terminal

This is necessary for terminal UI applications that need to handle keyboard input and mouse events directly. Exits raw mode.

Raw mode is a mode where the terminal does not process input, but instead passes it directly to the application. This means that:

  • Input is not echoed to the screen
  • Input is not line-buffered (characters are available immediately)
  • Some special characters are not processed by the terminal

Warning: This function is currently broken when used with the event server. If event.init_event_server was called, exiting raw mode will break input handling. The event server relies on raw mode being active to properly read events.

pub fn exit_raw() -> Result(Nil, TerminalError)
pub fn is_raw_mode() -> Bool
pub fn leave_alternative() -> String

Leave alternative screen. It is prefered not to use this directly. See LeaveAlternative.

pub fn scroll_down(n: Int) -> String

Scroll N rows down. It is prefered not to use this directly. See ScrollDown.

pub fn scroll_up(n: Int) -> String

Scroll N rows up. It is prefered not to use this directly. See ScrollUp.

pub fn set_size(x: Int, y: Int) -> String

Set window size. It does not work on most modern terminals due to security issues. It is prefered not to use this directly. See SetSize.

pub fn set_title(s: String) -> String

Sets terminal title. It is prefered not to use this directly. See SetTitle.

pub fn window_size() -> Result(#(Int, Int), TerminalError)

Returns current window size.

Search Document