class Termisu::Reader

Defined in:

termisu/reader.cr

Constant Summary

FD_SETSIZE = 1024

FD_SETSIZE limit for select(2). File descriptors >= this value cannot be used with select() and require poll() as a fallback.

Log = Termisu::Logs::Reader
MAX_EINTR_RETRIES = 100

Maximum retry attempts for EINTR before giving up. This prevents infinite loops in pathological signal storms.

Constructors

Instance Method Summary

Constructor Detail

def self.new(fd : Int32, buffer_size : Int32 = 128) #

Creates a new reader for the given file descriptor.

  • fd - File descriptor to read from
  • buffer_size - Internal buffer size (default: 128 bytes)

[View source]

Instance Method Detail

def available? : Bool #

Checks if data is available for reading.

Uses select(2) with zero timeout for non-blocking check.


[View source]
def clear_buffer #

Clears any buffered data.


[View source]
def close #

Closes the reader (does not close the file descriptor).


[View source]
def peek_byte : UInt8 | Nil #

Peeks at the next byte without consuming it.

Returns nil if no data is available.


[View source]
def read_byte : UInt8 | Nil #

Reads a single byte from the input.

Returns nil if no data is available or on EOF. This is a non-blocking operation when the terminal is in raw mode.


[View source]
def read_bytes(count : Int32) : Bytes | Nil #

Reads exactly count bytes from the input.

Returns nil if fewer than count bytes are available. Blocks until all bytes are read or timeout occurs.


[View source]
def wait_for_data(timeout_ms : Int32) : Bool #

Waits for data with a timeout.

  • timeout_ms - Timeout in milliseconds

Returns true if data becomes available, false on timeout.


[View source]