Package org.jline.terminal
Interface Terminal
-
- All Superinterfaces:
java.lang.AutoCloseable
,java.io.Closeable
,java.io.Flushable
- All Known Implementing Classes:
AbstractPosixTerminal
,AbstractTerminal
,AbstractWindowsTerminal
,DumbTerminal
,ExternalTerminal
,JansiWinSysTerminal
,JnaWinSysTerminal
,LineDisciplineTerminal
,PosixPtyTerminal
,PosixSysTerminal
public interface Terminal extends java.io.Closeable, java.io.Flushable
A terminal representing a virtual terminal on the computer. Terminals should be closed by calling theCloseable.close()
method in order to restore their original state.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
Terminal.MouseTracking
static class
Terminal.Signal
static interface
Terminal.SignalHandler
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
TYPE_DUMB
Type used for dumb terminals.static java.lang.String
TYPE_DUMB_COLOR
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description boolean
canPauseResume()
boolean
echo()
boolean
echo(boolean echo)
java.nio.charset.Charset
encoding()
Attributes
enterRawMode()
void
flush()
Attributes
getAttributes()
Returns the terminal attributes.boolean
getBooleanCapability(InfoCmp.Capability capability)
default Size
getBufferSize()
Retrieve the size of the window buffer.Cursor
getCursorPosition(java.util.function.IntConsumer discarded)
Query the terminal to report the cursor position.default int
getHeight()
java.lang.String
getName()
java.lang.Integer
getNumericCapability(InfoCmp.Capability capability)
ColorPalette
getPalette()
Color supportSize
getSize()
Retrieve the size of the visible windowjava.lang.String
getStringCapability(InfoCmp.Capability capability)
java.lang.String
getType()
default int
getWidth()
Terminal.SignalHandler
handle(Terminal.Signal signal, Terminal.SignalHandler handler)
boolean
hasFocusSupport()
Returnstrue
if the terminal has support for focus tracking.boolean
hasMouseSupport()
Returnstrue
if the terminal has support for mouse.java.io.InputStream
input()
Retrieve the input stream for this terminal.java.io.OutputStream
output()
Retrieve the output stream for this terminal.void
pause()
Stop reading the input stream.void
pause(boolean wait)
Stop reading the input stream and optionally wait for the underlying threads to finish.boolean
paused()
Check whether the terminal is currently reading the input stream or not.boolean
puts(InfoCmp.Capability capability, java.lang.Object... params)
void
raise(Terminal.Signal signal)
NonBlockingReader
reader()
Retrieve theReader
for this terminal.MouseEvent
readMouseEvent()
Read a MouseEvent from the terminal input stream.MouseEvent
readMouseEvent(java.util.function.IntSupplier reader)
Read a MouseEvent from the given input stream.void
resume()
Resume reading the input stream.void
setAttributes(Attributes attr)
Set the terminal attributes.void
setSize(Size size)
boolean
trackFocus(boolean tracking)
Enable or disable focus tracking mode.boolean
trackMouse(Terminal.MouseTracking tracking)
Change the mouse tracking mouse.java.io.PrintWriter
writer()
Retrieve theWriter
for this terminal.
-
-
-
Field Detail
-
TYPE_DUMB
static final java.lang.String TYPE_DUMB
Type used for dumb terminals.- See Also:
- Constant Field Values
-
TYPE_DUMB_COLOR
static final java.lang.String TYPE_DUMB_COLOR
- See Also:
- Constant Field Values
-
-
Method Detail
-
getName
java.lang.String getName()
-
handle
Terminal.SignalHandler handle(Terminal.Signal signal, Terminal.SignalHandler handler)
-
raise
void raise(Terminal.Signal signal)
-
reader
NonBlockingReader reader()
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
java.io.PrintWriter writer()
Retrieve theWriter
for this terminal. This is the standard way to write to this terminal.- Returns:
- The writer
-
encoding
java.nio.charset.Charset encoding()
- Returns:
- The terminal encoding
-
input
java.io.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:
reader()
-
output
java.io.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:
writer()
-
canPauseResume
boolean canPauseResume()
-
pause
void pause(boolean wait) throws java.lang.InterruptedException
Stop reading the input stream and optionally wait for the underlying threads to finish.- Parameters:
wait
-true
to wait until the terminal is actually paused- Throws:
java.lang.InterruptedException
- if the call has been interrupted
-
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.
-
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
void setAttributes(Attributes attr)
Set the terminal attributes. The terminal will perform a copy of the given attributes.- Parameters:
attr
- the new attributes
-
getSize
Size getSize()
Retrieve the size of the visible window- Returns:
- the visible terminal size
- See Also:
getBufferSize()
-
setSize
void setSize(Size size)
-
getWidth
default int getWidth()
-
getHeight
default int getHeight()
-
getBufferSize
default Size 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:
getSize()
-
flush
void flush()
- Specified by:
flush
in interfacejava.io.Flushable
-
getType
java.lang.String getType()
-
puts
boolean puts(InfoCmp.Capability capability, java.lang.Object... params)
-
getBooleanCapability
boolean getBooleanCapability(InfoCmp.Capability capability)
-
getNumericCapability
java.lang.Integer getNumericCapability(InfoCmp.Capability capability)
-
getStringCapability
java.lang.String getStringCapability(InfoCmp.Capability capability)
-
getCursorPosition
Cursor getCursorPosition(java.util.function.IntConsumer discarded)
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:
null
if cursor position reporting is not supported or a valid cursor position
-
hasMouseSupport
boolean hasMouseSupport()
Returnstrue
if the terminal has support for mouse.- Returns:
- whether mouse is supported by the terminal
- See Also:
trackMouse(MouseTracking)
-
trackMouse
boolean trackMouse(Terminal.MouseTracking tracking)
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_mouse
to 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:
true
if 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_mouse
in the stream immediately before reading the event.- Returns:
- the decoded mouse event.
- See Also:
trackMouse(MouseTracking)
-
readMouseEvent
MouseEvent readMouseEvent(java.util.function.IntSupplier reader)
Read a MouseEvent from the given input stream.- Parameters:
reader
- the input supplier- Returns:
- the decoded mouse event
-
hasFocusSupport
boolean hasFocusSupport()
Returnstrue
if the terminal has support for focus tracking.- Returns:
- whether focus tracking is supported by the terminal
- See Also:
trackFocus(boolean)
-
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:
true
if focus tracking is supported
-
getPalette
ColorPalette getPalette()
Color support
-
-