Class PosixSysTerminal
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
,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.Task
protected final NonBlockingInputStream
protected final Map
<Terminal.Signal, Object> protected final OutputStream
protected final NonBlockingReader
protected final PrintWriter
Fields inherited from class org.jline.terminal.impl.AbstractPosixTerminal
originalAttributes, pty
Fields inherited from class org.jline.terminal.impl.AbstractTerminal
bools, currentMouseTracking, encoding, handlers, ints, name, onClose, palette, status, stderrEncoding, stdinEncoding, stdoutEncoding, strings, type
Fields 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) PosixSysTerminal
(String name, String type, Pty pty, Charset encoding, Charset stdinEncoding, Charset stdoutEncoding, Charset stderrEncoding, boolean nativeSignals, Terminal.SignalHandler signalHandler) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
doClose()
handle
(Terminal.Signal signal, Terminal.SignalHandler handler) Registers a handler for the givenTerminal.Signal
.input()
Retrieve the input stream for this terminal.output()
Retrieve the output stream for this terminal.reader()
Retrieve theReader
for this terminal.writer()
Retrieve theWriter
for this terminal.Methods inherited from class org.jline.terminal.impl.AbstractPosixTerminal
getAttributes, getCursorPosition, getDefaultBackgroundColor, getDefaultForegroundColor, getProvider, getPty, getSize, getSystemStream, setAttributes, setSize, toString
Methods inherited from class org.jline.terminal.impl.AbstractTerminal
canPauseResume, checkInterrupted, close, echo, echo, echoSignal, encoding, enterRawMode, flush, getBooleanCapability, getCurrentMouseTracking, getKind, getName, getNumericCapability, getPalette, getStatus, getStatus, getStringCapability, getType, hasFocusSupport, hasMouseSupport, parseInfoCmp, pause, pause, paused, puts, raise, readMouseEvent, readMouseEvent, readMouseEvent, readMouseEvent, resume, setOnClose, stderrEncoding, stdinEncoding, stdoutEncoding, trackFocus, trackMouse
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.jline.terminal.Terminal
getBufferSize, getHeight, getWidth
-
Field Details
-
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 - Throws:
IOException
-
PosixSysTerminal
public PosixSysTerminal(String name, String type, Pty pty, Charset encoding, Charset stdinEncoding, Charset stdoutEncoding, Charset stderrEncoding, boolean nativeSignals, Terminal.SignalHandler signalHandler) throws IOException - Throws:
IOException
-
-
Method Details
-
handle
Description copied from interface:Terminal
Registers a handler for the givenTerminal.Signal
.This method allows the application to specify custom behavior when a particular signal is raised. The handler's
Terminal.SignalHandler.handle(Signal)
method will be called whenever the specified signal is raised.Note that the JVM does not easily allow catching the
Terminal.Signal.QUIT
signal (Ctrl+\), which typically causes a thread dump to be displayed. This signal handling is mainly effective when connecting through an SSH socket to a virtual terminal.Example usage:
Terminal terminal = TerminalBuilder.terminal(); // Handle window resize events terminal.handle(Signal.WINCH, signal -> { Size size = terminal.getSize(); terminal.writer().println("\nTerminal resized to " + size.getColumns() + "x" + size.getRows()); terminal.flush(); }); // Ignore interrupt signal terminal.handle(Signal.INT, SignalHandler.SIG_IGN);
- Specified by:
handle
in interfaceTerminal
- Overrides:
handle
in classAbstractTerminal
- Parameters:
signal
- the signal to register a handler forhandler
- the handler to be called when the signal is raised- Returns:
- the previous signal handler that was registered for this signal
- See Also:
-
reader
Description copied from interface:Terminal
Retrieve theReader
for this terminal. This is the standard way to read input from this terminal. The reader is non blocking.- Returns:
- The non blocking reader
-
writer
Description copied from interface:Terminal
Retrieve theWriter
for this terminal. This is the standard way to write to this terminal.- Returns:
- The writer
-
input
Description copied from interface:Terminal
Retrieve 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:
-
output
Description copied from interface:Terminal
Retrieve 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:
-
doClose
- Overrides:
doClose
in classAbstractPosixTerminal
- Throws:
IOException
-