Package org.jline.terminal
Interface Terminal
- All Superinterfaces:
AutoCloseable,Closeable,Flushable
- All Known Subinterfaces:
TerminalExt
- All Known Implementing Classes:
AbstractPosixTerminal,AbstractTerminal,AbstractWindowsTerminal,DumbTerminal,ExternalTerminal,LineDisciplineTerminal,PosixPtyTerminal,PosixSysTerminal
A terminal representing a virtual terminal on the computer.
Terminals should be closed by calling the
Closeable.close() method
in order to restore their original state.-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic enumstatic enumTypes of signals.static interfaceThe SignalHandler defines the interface used to trap signals and perform specific behaviors. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionbooleanbooleanecho()booleanecho(boolean echo) encoding()voidflush()Returns the terminal attributes.booleangetBooleanCapability(InfoCmp.Capability capability) default SizeRetrieve the size of the window buffer.getCursorPosition(IntConsumer discarded) Query the terminal to report the cursor position.default intgetName()getNumericCapability(InfoCmp.Capability capability) Color supportgetSize()Retrieve the size of the visible windowgetStringCapability(InfoCmp.Capability capability) getType()default intgetWidth()handle(Terminal.Signal signal, Terminal.SignalHandler handler) Registers a handler for the givenTerminal.Signal.booleanReturnstrueif the terminal has support for focus tracking.booleanReturnstrueif the terminal has support for mouse.input()Retrieve the input stream for this terminal.output()Retrieve the output stream for this terminal.voidpause()Stop 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.booleanputs(InfoCmp.Capability capability, Object... params) voidraise(Terminal.Signal signal) Raise the specific signal.reader()Retrieve theReaderfor this terminal.Read a MouseEvent from the terminal input stream.readMouseEvent(IntSupplier reader) Read a MouseEvent from the given input stream.voidresume()Resume reading the input stream.voidsetAttributes(Attributes attr) Set the terminal attributes.voidbooleantrackFocus(boolean tracking) Enable or disable focus tracking mode.booleantrackMouse(Terminal.MouseTracking tracking) Change the mouse tracking mouse.writer()Retrieve theWriterfor this terminal.
-
Field Details
-
TYPE_DUMB
-
TYPE_DUMB_COLOR
- See Also:
-
-
Method Details
-
getName
String getName() -
handle
Registers a handler for the givenTerminal.Signal.Note that the JVM does not easily allow catching the
Terminal.Signal.QUITsignal, which causes a thread dump to be displayed. This signal is mainly used when connecting through an SSH socket to a virtual terminal.- Parameters:
signal- the signal to register a handler forhandler- the handler- Returns:
- the previous signal handler
-
raise
Raise the specific signal. This is not method usually called by non system terminals. When accessing a terminal through a SSH or Telnet connection, signals may be conveyed by the protocol and thus need to be raised when reaching the terminal code. The terminals do that automatically when the terminal input stream has a character mapped toAttributes.ControlChar.VINTR,Attributes.ControlChar.VQUIT, orAttributes.ControlChar.VSUSP.- Parameters:
signal- the signal to raise
-
reader
NonBlockingReader reader()Retrieve theReaderfor this terminal. This is the standard way to read input from this terminal. The reader is non blocking.- Returns:
- The non blocking reader
-
writer
PrintWriter writer()Retrieve theWriterfor this terminal. This is the standard way to write to this terminal.- Returns:
- The writer
-
encoding
-
input
InputStream input()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 thereader()instead.- Returns:
- The input stream
- See Also:
-
output
OutputStream output()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 thewriter()instead.- Returns:
- The output stream
- See Also:
-
canPauseResume
-
pause
void pause()Stop reading the input stream.- See Also:
-
pause
Stop reading the input stream and optionally wait for the underlying threads to finish.- Parameters:
wait-trueto wait until the terminal is actually paused- Throws:
InterruptedException- if the call has been interrupted
-
resume
void resume()Resume reading the input stream.- See Also:
-
paused
boolean paused()Check 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.- Returns:
- whether the terminal is currently reading the input stream or not
- See Also:
-
enterRawMode
Attributes enterRawMode() -
echo
boolean echo() -
echo
boolean echo(boolean echo) -
getAttributes
Attributes getAttributes()Returns the terminal attributes. The returned object can be safely modified further used in a call tosetAttributes(Attributes).- Returns:
- the terminal attributes.
-
setAttributes
Set the terminal attributes. The terminal will perform a copy of the given attributes.- Parameters:
attr- the new attributes
-
getSize
-
setSize
-
getWidth
default int getWidth() -
getHeight
default int getHeight() -
getBufferSize
Retrieve the size of the window buffer. Some terminals can be configured to have a buffer size larger than the visible window size and provide scroll bars. In such cases, this method should attempt to return the size of the whole buffer. ThegetBufferSize()method can be used to avoid wrapping when using the terminal in a line editing mode, while thegetSize()method should be used when using full screen mode.- Returns:
- the terminal buffer size
- See Also:
-
flush
-
getType
String getType() -
puts
-
getBooleanCapability
-
getNumericCapability
-
getStringCapability
-
getCursorPosition
Query the terminal to report the cursor position. As the response is read from the input stream, some characters may be read before the cursor position is actually read. Those characters can be given back usingorg.jline.keymap.BindingReader#runMacro(String)- Parameters:
discarded- a consumer receiving discarded characters- Returns:
nullif cursor position reporting is not supported or a valid cursor position
-
hasMouseSupport
boolean hasMouseSupport()Returnstrueif the terminal has support for mouse.- Returns:
- whether mouse is supported by the terminal
- See Also:
-
trackMouse
Change the mouse tracking mouse. To start mouse tracking, this method must be called with a valid mouse tracking mode. Mouse events will be reported by writing theInfoCmp.Capability.key_mouseto the input stream. When this character sequence is detected, thereadMouseEvent()method can be called to actually read the corresponding mouse event.- Parameters:
tracking- the mouse tracking mode- Returns:
trueif mouse tracking is supported
-
readMouseEvent
MouseEvent readMouseEvent()Read a MouseEvent from the terminal input stream. Such an event must have been detected by scanning the terminal'sInfoCmp.Capability.key_mousein the stream immediately before reading the event.- Returns:
- the decoded mouse event.
- See Also:
-
readMouseEvent
Read a MouseEvent from the given input stream.- Parameters:
reader- the input supplier- Returns:
- the decoded mouse event
-
hasFocusSupport
boolean hasFocusSupport()Returnstrueif the terminal has support for focus tracking.- Returns:
- whether focus tracking is supported by the terminal
- See Also:
-
trackFocus
boolean trackFocus(boolean tracking) Enable or disable focus tracking mode. When focus tracking has been activated, each time the terminal grabs the focus, the string "\33[I" will be sent to the input stream and each time the focus is lost, the string "\33[O" will be sent to the input stream.- Parameters:
tracking- whether the focus tracking mode should be enabled or not- Returns:
trueif focus tracking is supported
-
getPalette
ColorPalette getPalette()Color support
-