Class PosixSysTerminal
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable,Sized,TerminalExt,Terminal
The PosixSysTerminal class provides a terminal implementation for POSIX systems (Linux, macOS, etc.) that uses the system standard input and output streams. It extends the AbstractPosixTerminal class and adds functionality specific to system stream-based terminals.
This implementation is used when connecting to the actual system terminal, such as when running a console application in a terminal window. It provides access to the standard input and output streams, allowing for interaction with the user through the terminal.
Key features of this implementation include:
- Direct access to system standard input and output
- Support for terminal attributes and size changes
- Support for non-blocking I/O
- Automatic restoration of terminal state on shutdown
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.jline.terminal.Terminal
Terminal.MouseTracking, Terminal.Signal, Terminal.SignalHandler -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final ShutdownHooks.Taskprotected final NonBlockingInputStreamprotected final Map<Terminal.Signal, Object> protected final OutputStreamprotected final TerminalProviderprotected final NonBlockingReaderprotected final PrintWriterFields inherited from class org.jline.terminal.impl.AbstractPosixTerminal
originalAttributes, ptyFields inherited from class org.jline.terminal.impl.AbstractTerminal
bools, closed, currentMouseTracking, encoding, handlers, inputEncoding, ints, name, onClose, outputEncoding, palette, status, strings, typeFields inherited from interface org.jline.terminal.Terminal
TYPE_DUMB, TYPE_DUMB_COLOR -
Constructor Summary
ConstructorsConstructorDescriptionPosixSysTerminal(String name, String type, Pty pty, Charset encoding, boolean nativeSignals, Terminal.SignalHandler signalHandler) Creates a POSIX system terminal backed by the provided PTY, using the same charset for input and output, and optionally enabling native signal handling.PosixSysTerminal(String name, String type, Pty pty, Charset encoding, Charset inputEncoding, Charset outputEncoding, boolean nativeSignals, Terminal.SignalHandler signalHandler) Creates a POSIX system terminal backed by the given PTY and character encodings, without a TerminalProvider.PosixSysTerminal(TerminalProvider provider, String name, String type, Pty pty, Charset encoding, Charset inputEncoding, Charset outputEncoding, boolean nativeSignals, Terminal.SignalHandler signalHandler) Create a POSIX system terminal backed by the provided PTY, initializing non-blocking input/output, reader/writer encodings, and optional native signal handlers. -
Method Summary
Modifier and TypeMethodDescriptionprotected voiddoClose()Closes the terminal and releases its resources: flushes pending output, removes the shutdown hook, unregisters any native signal handlers, performs superclass shutdown, and closes the reader.handle(Terminal.Signal signal, Terminal.SignalHandler handler) Install a new handler for the given signal and synchronize native registration when the handler changes.input()Retrieve the input stream for this terminal.output()Retrieve the output stream for this terminal.reader()Retrieve theReaderfor this terminal.booleanDetermine if grapheme cluster mode is supported for this terminal.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
canPauseResume, checkClosed, checkInterrupted, close, detectTrueColorSupport, echo, echo, echoSignal, encoding, enterRawMode, flush, getBooleanCapability, getCurrentMouseTracking, getGraphemeClusterMode, getKind, getName, getNumericCapability, getPalette, getStatus, getStatus, getStringCapability, getType, hasFocusSupport, hasMouseSupport, inputEncoding, isClusterGrouped, outputEncoding, parseInfoCmp, pause, pause, paused, puts, raise, readMouseEvent, readMouseEvent, readMouseEvent, readMouseEvent, resume, setGraphemeClusterMode, 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, getColumns, getHeight, getRows, getWidth, setSize
-
Field Details
-
provider
-
input
-
output
-
reader
-
writer
-
nativeHandlers
-
closer
-
-
Constructor Details
-
PosixSysTerminal
public PosixSysTerminal(String name, String type, Pty pty, Charset encoding, boolean nativeSignals, Terminal.SignalHandler signalHandler) throws IOException Creates a POSIX system terminal backed by the provided PTY, using the same charset for input and output, and optionally enabling native signal handling.- Parameters:
name- the terminal nametype- the terminal type (TERM)pty- the pseudo-terminal providing slave input/output streams for the terminalencoding- the charset used for both input and output encodingnativeSignals- if true, native OS signal handlers will be registeredsignalHandler- the initial handler to install for native signals- Throws:
IOException- if an I/O error occurs while initializing the terminal
-
PosixSysTerminal
public PosixSysTerminal(String name, String type, Pty pty, Charset encoding, Charset inputEncoding, Charset outputEncoding, boolean nativeSignals, Terminal.SignalHandler signalHandler) throws IOException Creates a POSIX system terminal backed by the given PTY and character encodings, without a TerminalProvider.- Parameters:
name- the terminal nametype- the terminal type (TERM)pty- the pseudoterminal providing slave input/output streamsencoding- the primary charset for the terminalinputEncoding- the charset used for input decodingoutputEncoding- the charset used for output encodingnativeSignals- whether native signal handlers should be registeredsignalHandler- the initial handler to install for native signals- Throws:
IOException- if an I/O error occurs while initializing the terminal
-
PosixSysTerminal
public PosixSysTerminal(TerminalProvider provider, String name, String type, Pty pty, Charset encoding, Charset inputEncoding, Charset outputEncoding, boolean nativeSignals, Terminal.SignalHandler signalHandler) throws IOException Create a POSIX system terminal backed by the provided PTY, initializing non-blocking input/output, reader/writer encodings, and optional native signal handlers.- Parameters:
provider- optional TerminalProvider used for native signal registration; may be nullname- the terminal nametype- the terminal type (TERM)pty- the PTY whose slave streams back this terminalencoding- the primary charset for the terminalinputEncoding- the charset used for the terminal readeroutputEncoding- the charset used for the terminal writernativeSignals- if true, register native OS signal handlers for all signalssignalHandler- the initial handler to install for native signals; if `SignalHandler.SIG_DFL`, default native handlers will be registered- Throws:
IOException- if the PTY streams or terminal I/O cannot be initialized
-
-
Method Details
-
handle
Install a new handler for the given signal and synchronize native registration when the handler changes. If the new handler differs from the previous one, registers a native default handler when the new handler is `SignalHandler.SIG_DFL`; otherwise registers a native handler that will raise the signal.- Specified by:
handlein interfaceTerminal- Overrides:
handlein classAbstractTerminal- Parameters:
signal- the signal to updatehandler- the new handler to install for the signal- Returns:
- the previous handler for the signal
- See Also:
-
supportsGraphemeClusterMode
public boolean supportsGraphemeClusterMode()Determine if grapheme cluster mode is supported for this terminal.- Specified by:
supportsGraphemeClusterModein interfaceTerminal- Overrides:
supportsGraphemeClusterModein classAbstractTerminal- Returns:
- `true` if grapheme cluster mode is supported, `false` otherwise; on Windows this always returns `false` to avoid writing a DECRQM probe to raw stdout/stderr that may not be a real PTY and could contaminate process output.
- 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.The returned reader is owned by this terminal and will be closed when the terminal is closed. Callers should not close it directly.
- Returns:
- The non blocking reader
-
writer
Description copied from interface:TerminalRetrieve theWriterfor this terminal. This is the standard way to write to this terminal.The returned writer is owned by this terminal and will be closed when the terminal is closed. Callers should not close it directly.
- Returns:
- The writer
-
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.The returned stream is owned by this terminal and will be closed when the terminal is closed. Callers should not close it directly.
- Returns:
- The input stream
- See Also:
-
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.The returned stream is owned by this terminal and will be closed when the terminal is closed. Callers should not close it directly.
- Returns:
- The output stream
- See Also:
-
doClose
Closes the terminal and releases its resources: flushes pending output, removes the shutdown hook, unregisters any native signal handlers, performs superclass shutdown, and closes the reader.- Overrides:
doClosein classAbstractPosixTerminal- Throws:
IOException- if an I/O error occurs while flushing or closing the terminal streams
-