Package org.jline.terminal.impl
Class AbstractWindowsTerminal<Console>
java.lang.Object
org.jline.terminal.impl.AbstractTerminal
org.jline.terminal.impl.AbstractWindowsTerminal<Console>
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
,TerminalExt
,Terminal
The AbstractWindowsTerminal is used as the base class for windows terminal.
Due to windows limitations, mostly the missing support for ansi sequences,
the only way to create a correct terminal is to use the windows api to set
character attributes, move the cursor, erasing, etc...
UTF-8 support is also lacking in windows and the code page supposed to
emulate UTF-8 is a bit broken. In order to work around this broken
code page, windows api WriteConsoleW is used directly. This means that
the writer() becomes the primary output, while the output() is bridged
to the writer() using a WriterOutputStream wrapper.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.jline.terminal.Terminal
Terminal.MouseTracking, Terminal.Signal, Terminal.SignalHandler
-
Field Summary
Modifier and TypeFieldDescriptionprotected final Attributes
protected final ShutdownHooks.Task
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
static final int
protected static final int
protected boolean
protected final Console
protected final NonBlockingInputStream
protected final Object
protected final Map
<Terminal.Signal, Object> protected final int
protected final int
protected final Console
protected final OutputStream
protected boolean
protected Thread
protected final NonBlockingReader
protected final Writer
protected Terminal.MouseTracking
static final String
static final String
static final String
static final String
protected final PrintWriter
Fields inherited from class org.jline.terminal.impl.AbstractTerminal
bools, encoding, handlers, ints, name, onClose, palette, status, strings, type
Fields inherited from interface org.jline.terminal.Terminal
TYPE_DUMB, TYPE_DUMB_COLOR
-
Constructor Summary
ConstructorDescriptionAbstractWindowsTerminal
(TerminalProvider provider, SystemStream systemStream, Writer writer, String name, String type, Charset encoding, boolean nativeSignals, Terminal.SignalHandler signalHandler, Console inConsole, int inConsoleMode, Console outConsole, int outConsoleMode) -
Method Summary
Modifier and TypeMethodDescriptionboolean
Whether this terminal supportsTerminal.pause()
andTerminal.resume()
calls.protected int
ctrl
(char key) protected void
doClose()
Returns the terminal attributes.protected abstract int
getConsoleMode
(Console console) protected String
getEscapeSequence
(short keyCode, int keyState) Returns theTerminalProvider
that created this terminal ornull
if the terminal was created with no provider.protected String
The underlying system stream, may beSystemStream.Output
,SystemStream.Error
, ornull
if this terminal is not bound to a system stream.handle
(Terminal.Signal signal, Terminal.SignalHandler handler) boolean
Returnstrue
if the terminal has support for focus tracking.input()
Retrieve the input stream for this terminal.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.protected abstract boolean
Read a single input event from the input buffer and process it.void
processInputChar
(char c) protected void
processKeyEvent
(boolean isKeyDown, short virtualKeyCode, char ch, int controlKeyState) protected void
pump()
reader()
Retrieve theReader
for this terminal.void
resume()
Resume reading the input stream.void
setAttributes
(Attributes attr) Set the terminal attributes.protected abstract void
setConsoleMode
(Console console, int mode) void
boolean
trackFocus
(boolean tracking) Enable or disable focus tracking mode.boolean
trackMouse
(Terminal.MouseTracking tracking) Change the mouse tracking mouse.protected void
writer()
Retrieve theWriter
for this terminal.Methods inherited from class org.jline.terminal.impl.AbstractTerminal
checkInterrupted, close, echo, echo, echoSignal, encoding, enterRawMode, flush, getBooleanCapability, getCursorPosition, getKind, getName, getNumericCapability, getPalette, getStatus, getStatus, getStringCapability, getType, hasMouseSupport, parseInfoCmp, puts, raise, readMouseEvent, readMouseEvent, setOnClose
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
getBufferSize, getHeight, getSize, getWidth
-
Field Details
-
TYPE_WINDOWS
- See Also:
-
TYPE_WINDOWS_256_COLOR
- See Also:
-
TYPE_WINDOWS_CONEMU
- See Also:
-
TYPE_WINDOWS_VTP
- See Also:
-
ENABLE_VIRTUAL_TERMINAL_PROCESSING
public static final int ENABLE_VIRTUAL_TERMINAL_PROCESSING- See Also:
-
ENABLE_PROCESSED_INPUT
protected static final int ENABLE_PROCESSED_INPUT- See Also:
-
ENABLE_LINE_INPUT
protected static final int ENABLE_LINE_INPUT- See Also:
-
ENABLE_ECHO_INPUT
protected static final int ENABLE_ECHO_INPUT- See Also:
-
ENABLE_WINDOW_INPUT
protected static final int ENABLE_WINDOW_INPUT- See Also:
-
ENABLE_MOUSE_INPUT
protected static final int ENABLE_MOUSE_INPUT- See Also:
-
ENABLE_INSERT_MODE
protected static final int ENABLE_INSERT_MODE- See Also:
-
ENABLE_QUICK_EDIT_MODE
protected static final int ENABLE_QUICK_EDIT_MODE- See Also:
-
slaveInputPipe
-
input
-
output
-
reader
-
writer
-
nativeHandlers
-
closer
-
attributes
-
inConsole
-
outConsole
-
originalInConsoleMode
protected final int originalInConsoleMode -
originalOutConsoleMode
protected final int originalOutConsoleMode -
lock
-
paused
protected boolean paused -
pump
-
tracking
-
focusTracking
protected boolean focusTracking
-
-
Constructor Details
-
AbstractWindowsTerminal
public AbstractWindowsTerminal(TerminalProvider provider, SystemStream systemStream, Writer writer, String name, String type, Charset encoding, boolean nativeSignals, Terminal.SignalHandler signalHandler, Console inConsole, int inConsoleMode, Console outConsole, int outConsoleMode) throws IOException - Throws:
IOException
-
-
Method Details
-
handle
- Specified by:
handle
in interfaceTerminal
- Overrides:
handle
in classAbstractTerminal
-
reader
Description copied from interface:Terminal
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
Description copied from interface:Terminal
Retrieve theWriter
for this terminal. This is the standard way to write to this terminal.- Returns:
- The writer
-
input
Description copied from interface:Terminal
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 theTerminal.reader()
instead.- Returns:
- The input stream
- See Also:
-
output
Description copied from interface:Terminal
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 theTerminal.writer()
instead.- Returns:
- The output stream
- See Also:
-
getAttributes
Description copied from interface:Terminal
Returns the terminal attributes. The returned object can be safely modified further used in a call toTerminal.setAttributes(Attributes)
.- Returns:
- the terminal attributes.
-
setAttributes
Description copied from interface:Terminal
Set the terminal attributes. The terminal will perform a copy of the given attributes.- Parameters:
attr
- the new attributes
-
updateConsoleMode
protected void updateConsoleMode() -
ctrl
protected int ctrl(char key) -
setSize
-
doClose
- Overrides:
doClose
in classAbstractTerminal
- Throws:
IOException
-
processKeyEvent
protected void processKeyEvent(boolean isKeyDown, short virtualKeyCode, char ch, int controlKeyState) throws IOException - Throws:
IOException
-
getEscapeSequence
-
getRawSequence
-
hasFocusSupport
public boolean hasFocusSupport()Description copied from interface:Terminal
Returnstrue
if the terminal has support for focus tracking.- Specified by:
hasFocusSupport
in interfaceTerminal
- Overrides:
hasFocusSupport
in classAbstractTerminal
- Returns:
- whether focus tracking is supported by the terminal
- See Also:
-
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
- Overrides:
trackFocus
in classAbstractTerminal
- Parameters:
tracking
- whether the focus tracking mode should be enabled or not- Returns:
true
if focus tracking is supported
-
canPauseResume
public boolean canPauseResume()Description copied from interface:Terminal
Whether this terminal supportsTerminal.pause()
andTerminal.resume()
calls.- Specified by:
canPauseResume
in interfaceTerminal
- Overrides:
canPauseResume
in classAbstractTerminal
- Returns:
- whether this terminal supports
Terminal.pause()
andTerminal.resume()
calls. - See Also:
-
pause
public void pause()Description copied from interface:Terminal
Stop reading the input stream.- Specified by:
pause
in interfaceTerminal
- Overrides:
pause
in classAbstractTerminal
- See Also:
-
pause
Description copied from interface:Terminal
Stop reading the input stream and optionally wait for the underlying threads to finish.- Specified by:
pause
in interfaceTerminal
- Overrides:
pause
in classAbstractTerminal
- 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
- Overrides:
resume
in classAbstractTerminal
- See Also:
-
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
- Overrides:
paused
in classAbstractTerminal
- Returns:
- whether the terminal is currently reading the input stream or not
- See Also:
-
pump
protected void pump() -
processInputChar
- Throws:
IOException
-
trackMouse
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
- Overrides:
trackMouse
in classAbstractTerminal
- Parameters:
tracking
- the mouse tracking mode- Returns:
true
if mouse tracking is supported
-
getConsoleMode
-
setConsoleMode
-
processConsoleInput
Read a single input event from the input buffer and process it.- Returns:
- true if new input was generated from the event
- Throws:
IOException
- if anything wrong happens
-
getProvider
Description copied from interface:TerminalExt
Returns theTerminalProvider
that created this terminal ornull
if the terminal was created with no provider. -
getSystemStream
Description copied from interface:TerminalExt
The underlying system stream, may beSystemStream.Output
,SystemStream.Error
, ornull
if this terminal is not bound to a system stream.
-