Interface Pty
- All Superinterfaces:
AutoCloseable, Closeable
- All Known Implementing Classes:
AbstractExecPty, CygwinPty, ExecPty
Represents a pseudo-terminal (PTY) providing master/slave input and output streams.
A PTY allows a program to interact with a terminal device, providing both
the master side (for the controlling process) and the slave side (for the terminal).
-
Method Summary
Modifier and TypeMethodDescriptionorg.aesh.terminal.AttributesgetAttr()Returns the current terminal attributes.Returns the master side input stream.Returns the master side output stream.org.aesh.terminal.tty.SizegetSize()Returns the current terminal size.Returns the slave side input stream.Returns the slave side output stream.default intpeek(long timeoutMs) Peeks at the next byte without consuming it, with a timeout.default intread(byte[] b, int off, int len, long timeoutMs) Reads multiple bytes with a timeout for the first byte.default intread(long timeoutMs) Reads a single byte with a timeout.voidsetAttr(org.aesh.terminal.Attributes attr) Sets the terminal attributes.default booleanWhether this PTY supports non-blocking read operations with timeouts.
-
Method Details
-
getMasterInput
-
getMasterOutput
OutputStream getMasterOutput()Returns the master side output stream.- Returns:
- the master output stream
-
getSlaveInput
-
getSlaveOutput
OutputStream getSlaveOutput()Returns the slave side output stream.- Returns:
- the slave output stream
-
getAttr
Returns the current terminal attributes.- Returns:
- the terminal attributes
- Throws:
IOException- if an I/O error occurs
-
setAttr
Sets the terminal attributes.- Parameters:
attr- the attributes to set- Throws:
IOException- if an I/O error occurs
-
getSize
Returns the current terminal size.- Returns:
- the terminal size
- Throws:
IOException- if an I/O error occurs
-
supportsNonBlockingRead
default boolean supportsNonBlockingRead()Whether this PTY supports non-blocking read operations with timeouts.- Returns:
- true if non-blocking reads are supported
-
read
Reads a single byte with a timeout.Default implementation delegates to
getSlaveInput().read(), ignoring the timeout (blocking).- Parameters:
timeoutMs- timeout in milliseconds; 0 for non-blocking, negative for infinite- Returns:
- the byte read (0-255), -1 for EOF, or
Terminal.READ_EXPIREDfor timeout - Throws:
IOException- if an I/O error occurs
-
peek
Peeks at the next byte without consuming it, with a timeout.Default implementation returns
Terminal.READ_EXPIRED(no peek support).- Parameters:
timeoutMs- timeout in milliseconds; 0 for non-blocking- Returns:
- the byte peeked (0-255), -1 for EOF, or
Terminal.READ_EXPIREDfor timeout - Throws:
IOException- if an I/O error occurs
-
read
Reads multiple bytes with a timeout for the first byte.After the first byte arrives (or timeout), reads additional bytes that are immediately available without blocking.
Default implementation delegates to
getSlaveInput().read(b, off, len), ignoring the timeout (blocking).- 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
Terminal.READ_EXPIREDfor timeout - Throws:
IOException- if an I/O error occurs
-