etui/backend

Types

pub type Backend(state) {
  Backend(
    init: fn() -> Result(state, Error),
    render: fn(state, List(RenderOp)) -> Result(state, Error),
    poll: fn(state, Int) -> Result(#(InputEvent, state), Error),
    next_size: fn(state) -> Result(#(TerminalSize, state), Error),
    cleanup: fn(state) -> Nil,
  )
}

Constructors

  • Backend(
      init: fn() -> Result(state, Error),
      render: fn(state, List(RenderOp)) -> Result(state, Error),
      poll: fn(state, Int) -> Result(#(InputEvent, state), Error),
      next_size: fn(state) -> Result(#(TerminalSize, state), Error),
      cleanup: fn(state) -> Nil,
    )
pub type Error {
  TerminalUnsupported(reason: String)
  IOError(reason: String)
  Interrupted
}

Constructors

  • TerminalUnsupported(reason: String)
  • IOError(reason: String)
  • Interrupted
pub type InputEvent {
  KeyPress(key: String)
  Resize(width: Int, height: Int)
  Tick
  MousePress(x: Int, y: Int, button: MouseButton)
  MouseRelease(x: Int, y: Int, button: MouseButton)
  MouseScroll(x: Int, y: Int, up: Bool)
}

Constructors

  • KeyPress(key: String)
  • Resize(width: Int, height: Int)
  • Tick
  • MousePress(x: Int, y: Int, button: MouseButton)

    Mouse button pressed. x/y are 0-based terminal cell coordinates.

  • MouseRelease(x: Int, y: Int, button: MouseButton)

    Mouse button released.

  • MouseScroll(x: Int, y: Int, up: Bool)

    Mouse wheel scrolled. up: True = scroll up, False = scroll down.

Mouse button identifier.

pub type MouseButton {
  MouseLeft
  MouseMiddle
  MouseRight
}

Constructors

  • MouseLeft
  • MouseMiddle
  • MouseRight

Terminal backend abstraction. Two implementations: Erlang + JS/Node.

pub type RenderOp {
  MoveCursor(x: Int, y: Int)
  Write(String)
  ClearScreen
  EnterAltScreen
  ExitAltScreen
  EnableMouse
  DisableMouse
}

Constructors

  • MoveCursor(x: Int, y: Int)
  • Write(String)
  • ClearScreen
  • EnterAltScreen
  • ExitAltScreen
  • EnableMouse

    Enable SGR mouse tracking (button + scroll events, pixel-precise coords).

  • DisableMouse

    Disable all mouse tracking.

pub type TerminalSize {
  TerminalSize(width: Int, height: Int)
}

Constructors

  • TerminalSize(width: Int, height: Int)

Values

pub fn cleanup(backend: Backend(state), state: state) -> Nil
pub fn clear_and_home() -> List(RenderOp)
pub fn init(backend: Backend(state)) -> Result(state, Error)
pub fn next_size(
  backend: Backend(state),
  state: state,
) -> Result(#(TerminalSize, state), Error)
pub fn poll(
  backend: Backend(state),
  state: state,
  timeout_ms: Int,
) -> Result(#(InputEvent, state), Error)
pub fn render(
  backend: Backend(state),
  state: state,
  ops: List(RenderOp),
) -> Result(state, Error)
Search Document