gsh/input/reader

The reader module provides an event-driven terminal polling loop for raw-mode TTY input.

When operating in raw mode, user keystrokes are received as unbuffered input streams. This module wraps the low-level etch event parser to poll TTY state, filter out non-keyboard signals (such as window resizes or mouse movements), intercept control chord modifiers (e.g., Ctrl+L or Ctrl+Left), and map raw events into the shell’s structured Key domain.

Values

pub fn read_key() -> key.Key

Polls the raw TTY stream for the next valid keyboard event.

Polling & CPU Yielding:

  • Calls input.read() to retrieve pending TTY events without thread blocking.
  • Yields thread execution via process.sleep(5) when no input is available (None), preventing high CPU utilization during idle REPL prompts.
  • Recursively discards non-keyboard terminal events (e.g., window size changes, mouse clicks) or stream parse errors until a valid key event is received.
Search Document