- 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>boolsprotected Charsetencodingprotected Map<Terminal.Signal,Terminal.SignalHandler>handlersprotected Map<InfoCmp.Capability,Integer>intsprotected Stringnameprotected RunnableonCloseprotected ColorPalettepaletteprotected Statusstatusprotected Map<InfoCmp.Capability,String>stringsprotected Stringtype-
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 booleancanPauseResume()Whether this terminal supportsTerminal.pause()andTerminal.resume()calls.protected voidcheckInterrupted()voidclose()protected voiddoClose()booleanecho()booleanecho(boolean echo)protected voidechoSignal(Terminal.Signal signal)Charsetencoding()Returns theCharsetthat should be used to encode characters forTerminal.input()andTerminal.output().AttributesenterRawMode()voidflush()booleangetBooleanCapability(InfoCmp.Capability capability)CursorgetCursorPosition(IntConsumer discarded)Query the terminal to report the cursor position.StringgetKind()StringgetName()IntegergetNumericCapability(InfoCmp.Capability capability)ColorPalettegetPalette()Color supportStatusgetStatus()StatusgetStatus(boolean create)StringgetStringCapability(InfoCmp.Capability capability)StringgetType()Terminal.SignalHandlerhandle(Terminal.Signal signal, Terminal.SignalHandler handler)booleanhasFocusSupport()Returnstrueif the terminal has support for focus tracking.booleanhasMouseSupport()Returnstrueif the terminal has support for mouse.protected voidparseInfoCmp()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)MouseEventreadMouseEvent()Read a MouseEvent from the terminal input stream.MouseEventreadMouseEvent(IntSupplier reader)Read a MouseEvent from the given input stream.voidresume()Resume reading the input stream.voidsetOnClose(Runnable onClose)booleantrackFocus(boolean tracking)Enable or disable focus tracking mode.booleantrackMouse(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:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
doClose
protected void doClose() throws IOException- Throws:
IOException
-
echoSignal
protected void echoSignal(Terminal.Signal signal)
-
enterRawMode
public Attributes enterRawMode()
- Specified by:
enterRawModein interfaceTerminal
-
getKind
public String getKind()
-
encoding
public Charset encoding()
Description copied from interface:TerminalReturns theCharsetthat 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:
getBooleanCapabilityin interfaceTerminal
-
getNumericCapability
public Integer getNumericCapability(InfoCmp.Capability capability)
- Specified by:
getNumericCapabilityin interfaceTerminal
-
getStringCapability
public String getStringCapability(InfoCmp.Capability capability)
- Specified by:
getStringCapabilityin interfaceTerminal
-
parseInfoCmp
protected void parseInfoCmp()
-
getCursorPosition
public Cursor getCursorPosition(IntConsumer discarded)
Description copied from interface:TerminalQuery 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:
getCursorPositionin interfaceTerminal- Parameters:
discarded- a consumer receiving discarded characters- Returns:
nullif cursor position reporting is not supported or a valid cursor position
-
hasMouseSupport
public boolean hasMouseSupport()
Description copied from interface:TerminalReturnstrueif the terminal has support for mouse.- Specified by:
hasMouseSupportin 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:TerminalChange 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, theTerminal.readMouseEvent()method can be called to actually read the corresponding mouse event.- Specified by:
trackMousein interfaceTerminal- Parameters:
tracking- the mouse tracking mode- Returns:
trueif mouse tracking is supported
-
readMouseEvent
public MouseEvent readMouseEvent()
Description copied from interface:TerminalRead 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.- Specified by:
readMouseEventin interfaceTerminal- Returns:
- the decoded mouse event.
- See Also:
Terminal.trackMouse(MouseTracking)
-
readMouseEvent
public MouseEvent readMouseEvent(IntSupplier reader)
Description copied from interface:TerminalRead a MouseEvent from the given input stream.- Specified by:
readMouseEventin interfaceTerminal- Parameters:
reader- the input supplier- Returns:
- the decoded mouse event
-
hasFocusSupport
public boolean hasFocusSupport()
Description copied from interface:TerminalReturnstrueif the terminal has support for focus tracking.- Specified by:
hasFocusSupportin 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:TerminalEnable 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:
trackFocusin interfaceTerminal- Parameters:
tracking- whether the focus tracking mode should be enabled or not- Returns:
trueif focus tracking is supported
-
checkInterrupted
protected void checkInterrupted() throws InterruptedIOException- Throws:
InterruptedIOException
-
canPauseResume
public boolean canPauseResume()
Description copied from interface:TerminalWhether this terminal supportsTerminal.pause()andTerminal.resume()calls.- Specified by:
canPauseResumein 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:TerminalStop reading the input stream.- Specified by:
pausein interfaceTerminal- See Also:
Terminal.resume(),Terminal.paused()
-
pause
public void pause(boolean wait) throws InterruptedExceptionDescription copied from interface:TerminalStop reading the input stream and optionally wait for the underlying threads to finish.- Specified by:
pausein interfaceTerminal- Parameters:
wait-trueto wait until the terminal is actually paused- Throws:
InterruptedException- if the call has been interrupted
-
resume
public void resume()
Description copied from interface:TerminalResume reading the input stream.- Specified by:
resumein interfaceTerminal- See Also:
Terminal.pause(),Terminal.paused()
-
paused
public boolean paused()
Description copied from interface:TerminalCheck 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:
pausedin 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:TerminalColor support- Specified by:
getPalettein interfaceTerminal
-
-