class Termisu::Termios

Overview

Manages terminal attributes for mode control.

Supports multiple modes via Terminal::Mode flags:

Defined in:

termisu/termios.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(fd : Int32) #

Creates a new Termios instance for the given file descriptor.

Parameters:

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

[View source]

Instance Method Detail

def current_mode : Terminal::Mode | Nil #

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


[View source]
def 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).


[View source]
def 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.


[View source]
def 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


[View source]