- java.lang.Object
-
- org.jline.terminal.impl.AbstractTerminal
-
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
,Terminal
- Direct Known Subclasses:
AbstractPosixTerminal
,AbstractWindowsTerminal
,DumbTerminal
,LineDisciplineTerminal
public abstract class AbstractTerminal extends Object implements Terminal
-
-
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 Set<InfoCmp.Capability>
bools
protected Charset
encoding
protected Map<Terminal.Signal,Terminal.SignalHandler>
handlers
protected Map<InfoCmp.Capability,Integer>
ints
protected String
name
protected Runnable
onClose
protected ColorPalette
palette
protected Status
status
protected Map<InfoCmp.Capability,String>
strings
protected String
type
-
Fields inherited from interface org.jline.terminal.Terminal
TYPE_DUMB, TYPE_DUMB_COLOR
-
-
Constructor Summary
Constructors Constructor Description AbstractTerminal(String name, String type)
AbstractTerminal(String name, String type, 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)
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(IntConsumer discarded)
Query the terminal to report the cursor position.String
getKind()
String
getName()
Integer
getNumericCapability(InfoCmp.Capability capability)
ColorPalette
getPalette()
Color supportStatus
getStatus()
Status
getStatus(boolean create)
String
getStringCapability(InfoCmp.Capability capability)
String
getType()
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.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, Object... params)
void
raise(Terminal.Signal signal)
MouseEvent
readMouseEvent()
Read a MouseEvent from the terminal input stream.MouseEvent
readMouseEvent(IntSupplier reader)
Read a MouseEvent from the given input stream.void
resume()
Resume reading the input stream.void
setOnClose(Runnable onClose)
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, toString, wait, wait, wait
-
Methods inherited from interface org.jline.terminal.Terminal
getAttributes, getBufferSize, getHeight, getSize, getWidth, input, output, reader, setAttributes, setSize, writer
-
-
-
-
Field Detail
-
name
protected final String name
-
type
protected final String type
-
encoding
protected final Charset encoding
-
handlers
protected final Map<Terminal.Signal,Terminal.SignalHandler> handlers
-
bools
protected final Set<InfoCmp.Capability> bools
-
ints
protected final Map<InfoCmp.Capability,Integer> ints
-
strings
protected final Map<InfoCmp.Capability,String> strings
-
palette
protected final ColorPalette palette
-
status
protected Status status
-
onClose
protected Runnable onClose
-
-
Constructor Detail
-
AbstractTerminal
public AbstractTerminal(String name, String type) throws IOException
- Throws:
IOException
-
AbstractTerminal
public AbstractTerminal(String name, String type, Charset encoding, Terminal.SignalHandler signalHandler) throws IOException
- Throws:
IOException
-
-
Method Detail
-
setOnClose
public void setOnClose(Runnable onClose)
-
getStatus
public Status getStatus()
-
getStatus
public Status getStatus(boolean create)
-
handle
public Terminal.SignalHandler handle(Terminal.Signal signal, Terminal.SignalHandler handler)
-
raise
public void raise(Terminal.Signal signal)
-
close
public final void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
doClose
protected void doClose() throws IOException
- Throws:
IOException
-
echoSignal
protected void echoSignal(Terminal.Signal signal)
-
enterRawMode
public Attributes enterRawMode()
- Specified by:
enterRawMode
in interfaceTerminal
-
getKind
public String getKind()
-
encoding
public 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, Object... params)
-
getBooleanCapability
public boolean getBooleanCapability(InfoCmp.Capability capability)
- Specified by:
getBooleanCapability
in interfaceTerminal
-
getNumericCapability
public Integer getNumericCapability(InfoCmp.Capability capability)
- Specified by:
getNumericCapability
in interfaceTerminal
-
getStringCapability
public String getStringCapability(InfoCmp.Capability capability)
- Specified by:
getStringCapability
in interfaceTerminal
-
parseInfoCmp
protected void parseInfoCmp()
-
getCursorPosition
public Cursor getCursorPosition(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(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 InterruptedIOException
- Throws:
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 InterruptedException
Description copied from interface:Terminal
Stop reading the input stream and optionally wait for the underlying threads to finish.- Specified by:
pause
in interfaceTerminal
- Parameters:
wait
-true
to wait until the terminal is actually paused- Throws:
InterruptedException
- if the call has been interrupted
-
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
-
-