class
Termisu::Terminal::Backend
- Termisu::Terminal::Backend
- Reference
- Object
Overview
Low-level terminal I/O combining TTY and Termios state management.
Provides basic terminal operations, managing both the underlying TTY file descriptors and terminal attributes (raw mode). Used internally by Terminal for I/O operations.
Example:
backend = Termisu::Terminal::Backend.new
backend.enable_raw_mode
backend.write("Hello, terminal!")
backend.flush
backend.close
Defined in:
termisu/terminal/backend.crConstructors
-
.new
Creates a new terminal backend, opening
/dev/ttyfor I/O.
Instance Method Summary
-
#close
Closes the terminal backend, disabling raw mode and closing TTY.
-
#disable_raw_mode
Disables raw mode, restoring original terminal attributes.
-
#enable_raw_mode
Enables raw mode for the terminal.
-
#flush
Flushes the output buffer to the terminal.
- #infd : Int32
- #outfd : Int32
-
#raw_mode? : Bool
Returns whether raw mode is currently enabled.
-
#read(buffer : Bytes) : Int32
Reads data from the terminal into the provided buffer.
-
#size : Tuple(Int32, Int32)
Returns the terminal size as {width, height}.
-
#with_raw_mode(&)
Executes a block with raw mode enabled, ensuring cleanup.
-
#write(data : String)
Writes data to the terminal output.
Constructor Detail
Creates a new terminal backend, opening /dev/tty for I/O.
Raises IO::Error if the TTY cannot be opened.
Instance Method Detail
Disables raw mode, restoring original terminal attributes.
This method is idempotent - calling it multiple times has no effect if raw mode is already disabled.
Enables raw mode for the terminal.
Raw mode disables input processing, canonical mode, echo, and signals, allowing direct character-by-character input without line buffering.
This method is idempotent - calling it multiple times has no effect if raw mode is already enabled.
Reads data from the terminal into the provided buffer.
Returns the number of bytes read, or 0 on EOF.
Raises IO::Error on read failure.
Returns the terminal size as {width, height}.
Uses the TIOCGWINSZ ioctl to query the terminal dimensions.
Raises IO::Error if the size cannot be determined.
Executes a block with raw mode enabled, ensuring cleanup.
Example:
backend.with_raw_mode do
# Raw mode operations here
end
# Raw mode automatically disabled