Class ExecPty
- java.lang.Object
-
- org.jline.terminal.impl.AbstractPty
-
- org.jline.terminal.impl.exec.ExecPty
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,Pty
public class ExecPty extends AbstractPty implements Pty
A pseudoterminal implementation that uses external commands to interact with the terminal.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:
AbstractPty
,Pty
-
-
Field Summary
-
Fields inherited from class org.jline.terminal.impl.AbstractPty
provider, systemStream
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
ExecPty(TerminalProvider provider, SystemStream systemStream, java.lang.String name)
Creates a new ExecPty instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes this Pty.static Pty
current(TerminalProvider provider, SystemStream systemStream)
Creates an ExecPty instance for the current terminal.static Attributes
doGetAttr(java.lang.String cfg)
protected java.lang.String
doGetConfig()
protected java.io.InputStream
doGetSlaveInput()
protected void
doSetAttr(Attributes attr)
Attributes
getAttr()
Returns the current terminal attributes for this PTY.protected java.util.List<java.lang.String>
getFlagsToSet(Attributes attr, Attributes current)
java.io.InputStream
getMasterInput()
Returns the input stream for the master side of the PTY.java.io.OutputStream
getMasterOutput()
Returns the output stream for the master side of the PTY.java.lang.String
getName()
Returns the name of the terminal device.Size
getSize()
Returns the current size (dimensions) of this PTY.java.io.OutputStream
getSlaveOutput()
Returns the output stream for the slave side of the PTY.void
setSize(Size size)
Sets the size (dimensions) of this PTY.java.lang.String
toString()
-
Methods inherited from class org.jline.terminal.impl.AbstractPty
checkInterrupted, getProvider, getSlaveInput, getSystemStream, newDescriptor, setAttr
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.jline.terminal.spi.Pty
getProvider, getSlaveInput, getSystemStream, setAttr
-
-
-
-
Constructor Detail
-
ExecPty
protected ExecPty(TerminalProvider provider, SystemStream systemStream, java.lang.String name)
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 Detail
-
current
public static Pty current(TerminalProvider provider, SystemStream systemStream) throws java.io.IOException
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:
java.io.IOException
- if the current terminal is not a TTY or if an error occurs while executing the 'tty' commandjava.lang.IllegalArgumentException
- if systemStream is not Output or Error
-
close
public void close() throws java.io.IOException
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:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Throws:
java.io.IOException
- if an I/O error occurs (never thrown by this implementation)
-
getName
public java.lang.String 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
public java.io.InputStream getMasterInput()
Description copied from interface:Pty
Returns 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:
getMasterInput
in interfacePty
- Returns:
- the master's input stream
-
getMasterOutput
public java.io.OutputStream getMasterOutput()
Description copied from interface:Pty
Returns 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:
getMasterOutput
in interfacePty
- Returns:
- the master's output stream
-
doGetSlaveInput
protected java.io.InputStream doGetSlaveInput() throws java.io.IOException
- Specified by:
doGetSlaveInput
in classAbstractPty
- Throws:
java.io.IOException
-
getSlaveOutput
public java.io.OutputStream getSlaveOutput() throws java.io.IOException
Description copied from interface:Pty
Returns 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:
getSlaveOutput
in interfacePty
- Returns:
- the slave's output stream
- Throws:
java.io.IOException
- if an I/O error occurs
-
getAttr
public Attributes getAttr() throws java.io.IOException
Description copied from interface:Pty
Returns 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:
getAttr
in interfacePty
- Returns:
- the current terminal attributes
- Throws:
java.io.IOException
- if an I/O error occurs- See Also:
Attributes
-
doSetAttr
protected void doSetAttr(Attributes attr) throws java.io.IOException
- Specified by:
doSetAttr
in classAbstractPty
- Throws:
java.io.IOException
-
getFlagsToSet
protected java.util.List<java.lang.String> getFlagsToSet(Attributes attr, Attributes current)
-
getSize
public Size getSize() throws java.io.IOException
Description copied from interface:Pty
Returns the current size (dimensions) of this PTY.The size includes the number of rows and columns in the terminal window.
-
doGetConfig
protected java.lang.String doGetConfig() throws java.io.IOException
- Throws:
java.io.IOException
-
doGetAttr
public static Attributes doGetAttr(java.lang.String cfg) throws java.io.IOException
- Throws:
java.io.IOException
-
setSize
public void setSize(Size size) throws java.io.IOException
Description copied from interface:Pty
Sets 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.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-