gsh/input/editor

The editor module implements a custom multiline line-editing engine built for raw-mode TTY input.

Standard input primitives (like erlang:get_line) block thread execution and lack support for custom keybindings, autocomplete menus, or 2D cursor traversal. This module replaces standard terminal input by capturing keystrokes directly, translating 1D buffer indices into 2D terminal coordinates, rendering floating autocompletion menus, and managing interactive command history navigation.

Types

Tracks the active state of an interactive prompt session.

pub type Editor {
  Editor(
    buffer: String,
    cursor: Int,
    history: List(String),
    history_index: Int,
    saved_buffer: option.Option(String),
    menu: option.Option(String),
  )
}

Constructors

  • Editor(
      buffer: String,
      cursor: Int,
      history: List(String),
      history_index: Int,
      saved_buffer: option.Option(String),
      menu: option.Option(String),
    )

    Arguments

    buffer

    The current raw input text buffer.

    cursor

    The 1D index offset of the cursor within the input buffer string.

    history

    Chronological list of previously executed commands.

    history_index

    Current pointer index when navigating through command history (-1 when typing active input).

    saved_buffer

    Temporarily stores unsubmitted buffer state when scrolling upwards into history.

    menu

    Pre-rendered multi-column string grid containing active autocompletion suggestions.

Values

pub fn read_line(
  prompt: String,
  history: List(String),
  completions: List(String),
) -> String

Initializes the interactive editor state and initiates the blocking keystroke listener loop.

Returns the final, accumulated input string once the user submits execution via the Enter key.

Search Document