Interface Terminal
- All Superinterfaces:
AutoCloseable, Closeable
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceHandler for terminal signals. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intReturn value indicating a read operation timed out without data. -
Method Summary
Modifier and TypeMethodDescriptiondevice()Get the terminal device for capability queries.booleanecho()Get the current echo state of the terminal.booleanecho(boolean echo) Set the echo state of the terminal.Get the terminal attributes.default Consumer<int[]> Get the code point consumer for this terminal.getName()Get the terminal name.getSize()Get the terminal size.handle(Signal signal, Terminal.SignalHandler handler) Register a signal handler for the specified signal.input()Get the terminal input stream.output()Get the terminal output stream.default intpeek(long timeoutMs) Peeks at the next byte from the terminal input without consuming it.voidRaise a signal on this terminal.default intread(byte[] b, int off, int len, long timeoutMs) Reads multiple bytes from the terminal input into a buffer with a timeout.default intread(long timeoutMs) Reads a single byte from the terminal input with a timeout.voidsetAttributes(Attributes attr) Set the terminal attributes.default booleanWhether this terminal supports non-blocking read operations with timeouts.
-
Field Details
-
READ_EXPIRED
static final int READ_EXPIREDReturn value indicating a read operation timed out without data.- See Also:
-
-
Method Details
-
getName
-
handle
Register a signal handler for the specified signal.- Parameters:
signal- the signal to handlehandler- the handler to register- Returns:
- the previous handler, or null if none
-
raise
-
input
-
output
-
echo
boolean echo()Get the current echo state of the terminal.- Returns:
- true if echo is enabled
-
echo
boolean echo(boolean echo) Set the echo state of the terminal.- Parameters:
echo- true to enable echo- Returns:
- the previous echo state
-
getAttributes
-
setAttributes
Set the terminal attributes.- Parameters:
attr- the attributes to set
-
getSize
-
device
-
getCodePointConsumer
Get the code point consumer for this terminal.- Returns:
- the code point consumer, or null if none
-
supportsNonBlockingRead
default boolean supportsNonBlockingRead()Whether this terminal supports non-blocking read operations with timeouts.When this returns
true,read(long)andpeek(long)provide timeout-based reads using platform-native mechanisms (e.g.,poll()on POSIX,WaitForSingleObjecton Windows). Whenfalse, those methods fall back to blocking reads viainput().- Returns:
- true if non-blocking reads are supported
-
read
Reads a single byte from the terminal input with a timeout.If data is available, returns the byte value (0-255). If the end of stream is reached, returns -1. If the timeout expires with no data available, returns
READ_EXPIRED(-2).The default implementation delegates to
input().read()(blocking, ignoring the timeout). Terminals that support non-blocking reads should override this to use platform-native polling.- Parameters:
timeoutMs- timeout in milliseconds; 0 means non-blocking (return immediately), negative means block indefinitely- Returns:
- the byte read (0-255), -1 for EOF, or
READ_EXPIREDfor timeout - Throws:
IOException- if an I/O error occurs
-
peek
Peeks at the next byte from the terminal input without consuming it.If data is available within the timeout, returns the byte value (0-255) but leaves it available for the next
read(long)call. If the end of stream is reached, returns -1. If the timeout expires with no data, returnsREAD_EXPIRED(-2).The default implementation returns
READ_EXPIRED(no peek support). Terminals that support non-blocking reads should override this to provide true peek functionality.- Parameters:
timeoutMs- timeout in milliseconds; 0 means non-blocking- Returns:
- the byte peeked (0-255), -1 for EOF, or
READ_EXPIREDfor timeout - Throws:
IOException- if an I/O error occurs
-
read
Reads multiple bytes from the terminal input into a buffer with a timeout.Reads the first byte using the specified timeout, then reads additional bytes that are immediately available (non-blocking). Returns the total number of bytes read, -1 for EOF, or
READ_EXPIREDif the timeout expires with no data.The default implementation delegates to
input().read(b, off, len)(blocking). Terminals that support non-blocking reads should override this to use platform-native polling.- Parameters:
b- the buffer to read intooff- the offset in the bufferlen- the maximum number of bytes to readtimeoutMs- timeout in milliseconds for the first byte- Returns:
- the number of bytes read, -1 for EOF, or
READ_EXPIREDfor timeout - Throws:
IOException- if an I/O error occurs
-