Package org.jline.terminal.impl
Class AbstractTerminal
- java.lang.Object
-
- org.jline.terminal.impl.AbstractTerminal
-
- All Implemented Interfaces:
java.io.Closeable
,java.io.Flushable
,java.lang.AutoCloseable
,TerminalExt
,Terminal
- Direct Known Subclasses:
AbstractPosixTerminal
,AbstractWindowsTerminal
,DumbTerminal
,LineDisciplineTerminal
public abstract class AbstractTerminal extends java.lang.Object implements TerminalExt
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.jline.terminal.Terminal
Terminal.MouseTracking, Terminal.Signal, Terminal.SignalHandler
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Set<InfoCmp.Capability>
bools
protected java.nio.charset.Charset
encoding
protected java.util.Map<Terminal.Signal,Terminal.SignalHandler>
handlers
protected java.util.Map<InfoCmp.Capability,java.lang.Integer>
ints
protected java.lang.String
name
protected java.lang.Runnable
onClose
protected ColorPalette
palette
protected Status
status
protected java.util.Map<InfoCmp.Capability,java.lang.String>
strings
protected java.lang.String
type
-
Fields inherited from interface org.jline.terminal.Terminal
TYPE_DUMB, TYPE_DUMB_COLOR
-
-
Constructor Summary
Constructors Constructor Description AbstractTerminal(java.lang.String name, java.lang.String type)
AbstractTerminal(java.lang.String name, java.lang.String type, java.nio.charset.Charset encoding, Terminal.SignalHandler signalHandler)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
canPauseResume()
Whether this terminal supportsTerminal.pause()
andTerminal.resume()
calls.protected void
checkInterrupted()
void
close()
protected void
doClose()
boolean
echo()
boolean
echo(boolean echo)
protected void
echoSignal(Terminal.Signal signal)
java.nio.charset.Charset
encoding()
Returns theCharset
that should be used to encode characters forTerminal.input()
andTerminal.output()
.Attributes
enterRawMode()
void
flush()
boolean
getBooleanCapability(InfoCmp.Capability capability)
Cursor
getCursorPosition(java.util.function.IntConsumer discarded)
Query the terminal to report the cursor position.java.lang.String
getKind()
java.lang.String
getName()
java.lang.Integer
getNumericCapability(InfoCmp.Capability capability)
ColorPalette
getPalette()
Color supportStatus
getStatus()
Status
getStatus(boolean create)
java.lang.String
getStringCapability(InfoCmp.Capability capability)
java.lang.String
getType()
Terminal.SignalHandler
handle(Terminal.Signal signal, Terminal.SignalHandler handler)
Registers a handler for the givenTerminal.Signal
.boolean
hasFocusSupport()
Returnstrue
if the terminal has support for focus tracking.boolean
hasMouseSupport()
Returnstrue
if the terminal has support for mouse.protected void
parseInfoCmp()
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)
Raise the specific signal.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
setOnClose(java.lang.Runnable onClose)
java.lang.String
toString()
boolean
trackFocus(boolean tracking)
Enable or disable focus tracking mode.boolean
trackMouse(Terminal.MouseTracking tracking)
Change the mouse tracking mouse.-
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
getAttributes, getBufferSize, getHeight, getSize, getWidth, input, output, reader, setAttributes, setSize, writer
-
Methods inherited from interface org.jline.terminal.spi.TerminalExt
getProvider, getSystemStream
-
-
-
-
Field Detail
-
name
protected final java.lang.String name
-
type
protected final java.lang.String type
-
encoding
protected final java.nio.charset.Charset encoding
-
handlers
protected final java.util.Map<Terminal.Signal,Terminal.SignalHandler> handlers
-
bools
protected final java.util.Set<InfoCmp.Capability> bools
-
ints
protected final java.util.Map<InfoCmp.Capability,java.lang.Integer> ints
-
strings
protected final java.util.Map<InfoCmp.Capability,java.lang.String> strings
-
palette
protected final ColorPalette palette
-
status
protected Status status
-
onClose
protected java.lang.Runnable onClose
-
-
Constructor Detail
-
AbstractTerminal
public AbstractTerminal(java.lang.String name, java.lang.String type) throws java.io.IOException
- Throws:
java.io.IOException
-
AbstractTerminal
public AbstractTerminal(java.lang.String name, java.lang.String type, java.nio.charset.Charset encoding, Terminal.SignalHandler signalHandler) throws java.io.IOException
- Throws:
java.io.IOException
-
-
Method Detail
-
setOnClose
public void setOnClose(java.lang.Runnable onClose)
-
getStatus
public Status getStatus()
-
getStatus
public Status getStatus(boolean create)
-
handle
public Terminal.SignalHandler handle(Terminal.Signal signal, Terminal.SignalHandler handler)
Description copied from interface:Terminal
Registers a handler for the givenTerminal.Signal
.Note that the JVM does not easily allow catching the
Terminal.Signal.QUIT
signal, which causes a thread dump to be displayed. This signal is mainly used when connecting through an SSH socket to a virtual terminal.
-
raise
public void raise(Terminal.Signal signal)
Description copied from interface:Terminal
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
.
-
close
public final void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Throws:
java.io.IOException
-
doClose
protected void doClose() throws java.io.IOException
- Throws:
java.io.IOException
-
echoSignal
protected void echoSignal(Terminal.Signal signal)
-
enterRawMode
public Attributes enterRawMode()
- Specified by:
enterRawMode
in interfaceTerminal
-
getKind
public java.lang.String getKind()
-
encoding
public java.nio.charset.Charset encoding()
Description copied from interface:Terminal
Returns theCharset
that should be used to encode characters forTerminal.input()
andTerminal.output()
.
-
flush
public void flush()
-
puts
public boolean puts(InfoCmp.Capability capability, java.lang.Object... params)
-
getBooleanCapability
public boolean getBooleanCapability(InfoCmp.Capability capability)
- Specified by:
getBooleanCapability
in interfaceTerminal
-
getNumericCapability
public java.lang.Integer getNumericCapability(InfoCmp.Capability capability)
- Specified by:
getNumericCapability
in interfaceTerminal
-
getStringCapability
public java.lang.String getStringCapability(InfoCmp.Capability capability)
- Specified by:
getStringCapability
in interfaceTerminal
-
parseInfoCmp
protected void parseInfoCmp()
-
getCursorPosition
public Cursor getCursorPosition(java.util.function.IntConsumer discarded)
Description copied from interface:Terminal
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)
- Specified by:
getCursorPosition
in interfaceTerminal
- Parameters:
discarded
- a consumer receiving discarded characters- Returns:
null
if cursor position reporting is not supported or a valid cursor position
-
hasMouseSupport
public boolean hasMouseSupport()
Description copied from interface:Terminal
Returnstrue
if the terminal has support for mouse.- Specified by:
hasMouseSupport
in interfaceTerminal
- Returns:
- whether mouse is supported by the terminal
- See Also:
Terminal.trackMouse(MouseTracking)
-
trackMouse
public boolean trackMouse(Terminal.MouseTracking tracking)
Description copied from interface:Terminal
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, theTerminal.readMouseEvent()
method can be called to actually read the corresponding mouse event.- Specified by:
trackMouse
in interfaceTerminal
- Parameters:
tracking
- the mouse tracking mode- Returns:
true
if mouse tracking is supported
-
readMouseEvent
public MouseEvent readMouseEvent()
Description copied from interface:Terminal
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.- Specified by:
readMouseEvent
in interfaceTerminal
- Returns:
- the decoded mouse event.
- See Also:
Terminal.trackMouse(MouseTracking)
-
readMouseEvent
public MouseEvent readMouseEvent(java.util.function.IntSupplier reader)
Description copied from interface:Terminal
Read a MouseEvent from the given input stream.- Specified by:
readMouseEvent
in interfaceTerminal
- Parameters:
reader
- the input supplier- Returns:
- the decoded mouse event
-
hasFocusSupport
public boolean hasFocusSupport()
Description copied from interface:Terminal
Returnstrue
if the terminal has support for focus tracking.- Specified by:
hasFocusSupport
in interfaceTerminal
- Returns:
- whether focus tracking is supported by the terminal
- See Also:
Terminal.trackFocus(boolean)
-
trackFocus
public boolean trackFocus(boolean tracking)
Description copied from interface:Terminal
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.- Specified by:
trackFocus
in interfaceTerminal
- Parameters:
tracking
- whether the focus tracking mode should be enabled or not- Returns:
true
if focus tracking is supported
-
checkInterrupted
protected void checkInterrupted() throws java.io.InterruptedIOException
- Throws:
java.io.InterruptedIOException
-
canPauseResume
public boolean canPauseResume()
Description copied from interface:Terminal
Whether this terminal supportsTerminal.pause()
andTerminal.resume()
calls.- Specified by:
canPauseResume
in interfaceTerminal
- Returns:
- whether this terminal supports
Terminal.pause()
andTerminal.resume()
calls. - See Also:
Terminal.paused()
,Terminal.pause()
,Terminal.resume()
-
pause
public void pause()
Description copied from interface:Terminal
Stop reading the input stream.- Specified by:
pause
in interfaceTerminal
- See Also:
Terminal.resume()
,Terminal.paused()
-
pause
public void pause(boolean wait) throws java.lang.InterruptedException
Description copied from interface:Terminal
Stop reading the input stream and optionally wait for the underlying threads to finish.
-
resume
public void resume()
Description copied from interface:Terminal
Resume reading the input stream.- Specified by:
resume
in interfaceTerminal
- See Also:
Terminal.pause()
,Terminal.paused()
-
paused
public boolean paused()
Description copied from interface:Terminal
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.- Specified by:
paused
in interfaceTerminal
- Returns:
- whether the terminal is currently reading the input stream or not
- See Also:
Terminal.pause()
,Terminal.resume()
-
getPalette
public ColorPalette getPalette()
Description copied from interface:Terminal
Color support- Specified by:
getPalette
in interfaceTerminal
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-