Class PosixPtyTerminal
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable,TerminalExt,Terminal
The PosixPtyTerminal class provides a terminal implementation for POSIX systems (Linux, macOS, etc.) that uses a pseudoterminal (PTY) for terminal operations. It extends the AbstractPosixTerminal class and adds functionality specific to PTY-based terminals.
This implementation is used when a full terminal emulation is needed, such as when creating a terminal for an external process or when connecting to a remote terminal. It provides access to the master and slave sides of the PTY, allowing for bidirectional communication with the terminal.
Key features of this implementation include:
- Full terminal emulation using a pseudoterminal
- Support for terminal attributes and size changes
- Access to both master and slave sides of the PTY
- Support for non-blocking I/O
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.jline.terminal.Terminal
Terminal.MouseTracking, Terminal.Signal, Terminal.SignalHandler -
Field Summary
Fields inherited from class org.jline.terminal.impl.AbstractPosixTerminal
originalAttributes, ptyFields inherited from class org.jline.terminal.impl.AbstractTerminal
bools, currentMouseTracking, encoding, handlers, ints, name, onClose, palette, status, strings, typeFields inherited from interface org.jline.terminal.Terminal
TYPE_DUMB, TYPE_DUMB_COLOR -
Constructor Summary
ConstructorsConstructorDescriptionPosixPtyTerminal(String name, String type, Pty pty, InputStream in, OutputStream out, Charset encoding) PosixPtyTerminal(String name, String type, Pty pty, InputStream in, OutputStream out, Charset encoding, Terminal.SignalHandler signalHandler) PosixPtyTerminal(String name, String type, Pty pty, InputStream in, OutputStream out, Charset encoding, Terminal.SignalHandler signalHandler, boolean paused) -
Method Summary
Modifier and TypeMethodDescriptionbooleanWhether this terminal supportsTerminal.pause()andTerminal.resume()calls.protected voiddoClose()input()Retrieve the input stream for this terminal.output()Retrieve the output stream for this terminal.voidpause()Temporarily stops reading the input stream.voidpause(boolean wait) Stop reading the input stream and optionally wait for the underlying threads to finish.booleanpaused()Check whether the terminal is currently reading the input stream or not.reader()Retrieve theReaderfor this terminal.voidresume()Resumes reading the input stream after it has been paused.writer()Retrieve theWriterfor this terminal.Methods inherited from class org.jline.terminal.impl.AbstractPosixTerminal
getAttributes, getCursorPosition, getDefaultBackgroundColor, getDefaultForegroundColor, getProvider, getPty, getSize, getSystemStream, setAttributes, setSize, toStringMethods inherited from class org.jline.terminal.impl.AbstractTerminal
checkInterrupted, close, echo, echo, echoSignal, encoding, enterRawMode, flush, getBooleanCapability, getCurrentMouseTracking, getKind, getName, getNumericCapability, getPalette, getStatus, getStatus, getStringCapability, getType, handle, hasFocusSupport, hasMouseSupport, parseInfoCmp, puts, raise, readMouseEvent, readMouseEvent, readMouseEvent, readMouseEvent, setOnClose, trackFocus, trackMouseMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.jline.terminal.Terminal
getBufferSize, getHeight, getWidth
-
Constructor Details
-
PosixPtyTerminal
public PosixPtyTerminal(String name, String type, Pty pty, InputStream in, OutputStream out, Charset encoding) throws IOException - Throws:
IOException
-
PosixPtyTerminal
public PosixPtyTerminal(String name, String type, Pty pty, InputStream in, OutputStream out, Charset encoding, Terminal.SignalHandler signalHandler) throws IOException - Throws:
IOException
-
PosixPtyTerminal
public PosixPtyTerminal(String name, String type, Pty pty, InputStream in, OutputStream out, Charset encoding, Terminal.SignalHandler signalHandler, boolean paused) throws IOException - Throws:
IOException
-
-
Method Details
-
input
Description copied from interface:TerminalRetrieve the input stream for this terminal. In some rare cases, there may be a need to access the terminal input stream directly. In the usual cases, use theTerminal.reader()instead.- Returns:
- The input stream
- See Also:
-
reader
Description copied from interface:TerminalRetrieve theReaderfor this terminal. This is the standard way to read input from this terminal. The reader is non blocking.- Returns:
- The non blocking reader
-
output
Description copied from interface:TerminalRetrieve the output stream for this terminal. In some rare cases, there may be a need to access the terminal output stream directly. In the usual cases, use theTerminal.writer()instead.- Returns:
- The output stream
- See Also:
-
writer
Description copied from interface:TerminalRetrieve theWriterfor this terminal. This is the standard way to write to this terminal.- Returns:
- The writer
-
doClose
- Overrides:
doClosein classAbstractPosixTerminal- Throws:
IOException
-
canPauseResume
public boolean canPauseResume()Description copied from interface:TerminalWhether this terminal supportsTerminal.pause()andTerminal.resume()calls.- Specified by:
canPauseResumein interfaceTerminal- Overrides:
canPauseResumein classAbstractTerminal- Returns:
- whether this terminal supports
Terminal.pause()andTerminal.resume()calls. - See Also:
-
pause
public void pause()Description copied from interface:TerminalTemporarily stops reading the input stream.This method pauses the terminal's input processing, which can be useful when transferring control to a subprocess or when the terminal needs to be in a specific state for certain operations. While paused, the terminal will not process input or handle signals that would normally be triggered by special characters in the input stream.
This method returns immediately without waiting for the terminal to actually pause. To wait until the terminal has fully paused, use
Terminal.pause(boolean)with a value oftrue.Example usage:
Terminal terminal = TerminalBuilder.terminal(); // Pause terminal input processing before running a subprocess terminal.pause(); // Run subprocess that takes control of the terminal Process process = new ProcessBuilder("vim").inheritIO().start(); process.waitFor(); // Resume terminal input processing terminal.resume();- Specified by:
pausein interfaceTerminal- Overrides:
pausein classAbstractTerminal- See Also:
-
pause
Description copied from interface:TerminalStop reading the input stream and optionally wait for the underlying threads to finish.- Specified by:
pausein interfaceTerminal- Overrides:
pausein classAbstractTerminal- Parameters:
wait-trueto wait until the terminal is actually paused- Throws:
InterruptedException- if the call has been interrupted
-
resume
public void resume()Description copied from interface:TerminalResumes reading the input stream after it has been paused.This method restarts the terminal's input processing after it has been temporarily stopped using
Terminal.pause()orTerminal.pause(boolean). Once resumed, the terminal will continue to process input and handle signals triggered by special characters in the input stream.Calling this method when the terminal is not paused has no effect.
Example usage:
Terminal terminal = TerminalBuilder.terminal(); // Pause terminal input processing terminal.pause(); // Perform operations while terminal input is paused... // Resume terminal input processing terminal.resume();
- Specified by:
resumein interfaceTerminal- Overrides:
resumein classAbstractTerminal- See Also:
-
paused
public boolean paused()Description copied from interface:TerminalCheck whether the terminal is currently reading the input stream or not. In order to process signal as quickly as possible, the terminal need to read the input stream and buffer it internally so that it can detect specific characters in the input stream (Ctrl+C, Ctrl+D, etc...) and raise the appropriate signals. However, there are some cases where this processing should be disabled, for example when handing the terminal control to a subprocess.- Specified by:
pausedin interfaceTerminal- Overrides:
pausedin classAbstractTerminal- Returns:
- whether the terminal is currently reading the input stream or not
- See Also:
-