class
Termisu::Termios
- Termisu::Termios
- Reference
- Object
Overview
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
Defined in:
termisu/termios.crConstructors
-
.new(fd : Int32)
Creates a new Termios instance for the given file descriptor.
Instance Method Summary
-
#current_mode : Terminal::Mode | Nil
Returns the current terminal mode, or nil if not yet set.
-
#enable_raw_mode
Enables raw mode on the terminal.
-
#restore
Restores original terminal attributes saved during first mode change.
-
#set_mode(mode : Terminal::Mode)
Sets terminal to specific mode using Terminal::Mode flags.
Constructor Detail
Creates a new Termios instance for the given file descriptor.
Parameters:
- fd: File descriptor (typically STDIN.fd for terminal input)
Instance Method Detail
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).
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.
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