Class ExecPty
- All Implemented Interfaces:
Closeable,AutoCloseable,Pty
The ExecPty class provides a Pty implementation that uses external commands (such as stty, tput, etc.) to interact with the terminal. This approach allows JLine to work in environments where native libraries are not available or cannot be used, by relying on standard command-line utilities that are typically available on Unix-like systems.
This implementation executes external commands to perform operations such as:
- Getting and setting terminal attributes
- Getting and setting terminal size
- Determining the current terminal device
The ExecPty is typically used as a fallback when more direct methods of terminal interaction (such as JNI or JNA) are not available. While it provides good compatibility, it may have higher overhead due to the need to spawn external processes for many operations.
- See Also:
-
Field Summary
Fields inherited from class org.jline.terminal.impl.AbstractPty
provider, systemStream -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedExecPty(TerminalProvider provider, SystemStream systemStream, String name) Creates a new ExecPty instance. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes this Pty.static Ptycurrent(TerminalProvider provider, SystemStream systemStream) Creates an ExecPty instance for the current terminal.static Attributesprotected Stringprotected InputStreamprotected voiddoSetAttr(Attributes attr) getAttr()Returns the current terminal attributes for this PTY.getFlagsToSet(Attributes attr, Attributes current) Returns the input stream for the master side of the PTY.Returns the output stream for the master side of the PTY.getName()Returns the name of the terminal device.getSize()Returns the current size (dimensions) of this PTY.Returns the output stream for the slave side of the PTY.voidSets the size (dimensions) of this PTY.toString()Methods inherited from class org.jline.terminal.impl.AbstractPty
checkInterrupted, getProvider, getSlaveInput, getSystemStream, newDescriptor, setAttrMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.jline.terminal.spi.Pty
getProvider, getSlaveInput, getSystemStream, setAttr
-
Constructor Details
-
ExecPty
Creates a new ExecPty instance.This constructor creates a new ExecPty instance with the specified provider, system stream, and terminal device name. It is protected because instances should typically be created using the
current(TerminalProvider, SystemStream)method.- Parameters:
provider- the terminal provider that will own this PtysystemStream- the system stream associated with this Ptyname- the name of the terminal device (e.g., "/dev/tty")
-
-
Method Details
-
current
Creates an ExecPty instance for the current terminal.This method creates an ExecPty instance for the current terminal by executing the 'tty' command to determine the terminal device name. It is used to obtain a Pty object that can interact with the current terminal using external commands.
- Parameters:
provider- the terminal provider that will own this PtysystemStream- the system stream (must be Output or Error) associated with this Pty- Returns:
- a new ExecPty instance for the current terminal
- Throws:
IOException- if the current terminal is not a TTY or if an error occurs while executing the 'tty' commandIllegalArgumentException- if systemStream is not Output or Error
-
close
Closes this Pty.This implementation does nothing, as there are no resources to release. The terminal device is not actually opened by this class, so it does not need to be closed.
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException- if an I/O error occurs (never thrown by this implementation)
-
getName
Returns the name of the terminal device.This method returns the name of the terminal device associated with this Pty, which was determined when the Pty was created. This is typically a device path such as "/dev/tty" or "/dev/pts/0".
- Returns:
- the name of the terminal device
-
getMasterInput
Description copied from interface:PtyReturns the input stream for the master side of the PTY.This stream receives data that has been written to the slave's output stream. Terminal emulators typically read from this stream to get the output from processes running in the terminal.
- Specified by:
getMasterInputin interfacePty- Returns:
- the master's input stream
-
getMasterOutput
Description copied from interface:PtyReturns the output stream for the master side of the PTY.Data written to this stream will be available for reading from the slave's input stream. Terminal emulators typically write to this stream to send input to processes running in the terminal.
- Specified by:
getMasterOutputin interfacePty- Returns:
- the master's output stream
-
doGetSlaveInput
- Specified by:
doGetSlaveInputin classAbstractPty- Throws:
IOException
-
getSlaveOutput
Description copied from interface:PtyReturns the output stream for the slave side of the PTY.Data written to this stream will be available for reading from the master's input stream. Processes running in the terminal write to this stream to produce their output.
- Specified by:
getSlaveOutputin interfacePty- Returns:
- the slave's output stream
- Throws:
IOException- if an I/O error occurs
-
getAttr
Description copied from interface:PtyReturns the current terminal attributes for this PTY.Terminal attributes control various aspects of terminal behavior, such as echo settings, line discipline, and control characters.
- Specified by:
getAttrin interfacePty- Returns:
- the current terminal attributes
- Throws:
IOException- if an I/O error occurs- See Also:
-
doSetAttr
- Specified by:
doSetAttrin classAbstractPty- Throws:
IOException
-
getFlagsToSet
-
getSize
Description copied from interface:PtyReturns the current size (dimensions) of this PTY.The size includes the number of rows and columns in the terminal window.
- Specified by:
getSizein interfacePty- Returns:
- the current terminal size
- Throws:
IOException- if an I/O error occurs- See Also:
-
doGetConfig
- Throws:
IOException
-
doGetAttr
- Throws:
IOException
-
setSize
Description copied from interface:PtySets the size (dimensions) of this PTY.This method changes the number of rows and columns in the terminal window. When the size changes, a SIGWINCH signal is typically sent to processes running in the terminal.
- Specified by:
setSizein interfacePty- Parameters:
size- the new terminal size to set- Throws:
IOException- if an I/O error occurs- See Also:
-
toString
-