class

Termisu::Termios

Inherits Reference / Object

Manages terminal attributes for mode control.

Supports multiple modes via Terminal::Mode flags:

  • Raw: No processing (current Termisu default for TUI)
  • Cooked: Full line editing, echo, signals (shell-out)
  • Cbreak: Char-by-char with echo and signals
  • Password: Line editing without echo
  • SemiRaw: Raw with signal handling

Constructors

new(fd : Int32)

Creates a new Termios instance for the given file descriptor.

Parameters:

  • fd: File descriptor (typically STDIN.fd for terminal input)
Source

Instance methods

current_mode

Returns the current terminal mode, or nil if not yet set.

Source
enable_raw_mode

Enables raw mode on the terminal.

Saves current attributes and modifies terminal to disable:

  • Input processing and special character handling
  • Echo of typed characters
  • Canonical (line-buffered) mode
  • Signal generation from Ctrl+C, Ctrl+Z, etc.

This is a convenience method equivalent to set_mode(Terminal::Mode.raw).

Source
restore

Restores original terminal attributes saved during first mode change.

Safe to call even if no mode was ever set (no-op). Resets current_mode tracking to nil.

Source
set_mode(mode : Terminal::Mode)

Sets terminal to specific mode using Terminal::Mode flags.

Saves original terminal state on first call, then applies the requested mode flags to control terminal behavior.

Parameters:

  • mode: Terminal::Mode flags specifying desired behavior

Example:

termios.set_mode(Terminal::Mode.cooked)   # Shell-out mode
termios.set_mode(Terminal::Mode.password) # No echo, line editing
termios.set_mode(Terminal::Mode.raw)      # Full TUI control

ameba:disable Naming/AccessorMethodName

Source