Package org.jline.terminal.impl
Class AbstractWindowsTerminal
- java.lang.Object
-
- org.jline.terminal.impl.AbstractTerminal
-
- org.jline.terminal.impl.AbstractWindowsTerminal
-
- All Implemented Interfaces:
java.io.Closeable
,java.io.Flushable
,java.lang.AutoCloseable
,Terminal
- Direct Known Subclasses:
JansiWinSysTerminal
,JnaWinSysTerminal
public abstract class AbstractWindowsTerminal extends AbstractTerminal
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
Fields Modifier and Type Field Description (package private) static int
ALT_FLAG
protected Attributes
attributes
(package private) static int
CAPSLOCK_ON
protected ShutdownHooks.Task
closer
private boolean
closing
(package private) static int
CTRL_FLAG
protected static int
ENABLE_ECHO_INPUT
protected static int
ENABLE_INSERT_MODE
protected static int
ENABLE_LINE_INPUT
protected static int
ENABLE_MOUSE_INPUT
protected static int
ENABLE_PROCESSED_INPUT
protected static int
ENABLE_QUICK_EDIT_MODE
static int
ENABLE_VIRTUAL_TERMINAL_PROCESSING
protected static int
ENABLE_WINDOW_INPUT
protected boolean
focusTracking
protected NonBlockingInputStream
input
(package private) static int
LEFT_ALT_PRESSED
(package private) static int
LEFT_CTRL_PRESSED
protected java.lang.Object
lock
protected java.util.Map<Terminal.Signal,java.lang.Object>
nativeHandlers
(package private) static int
NUMLOCK_ON
protected int
originalConsoleMode
protected java.io.OutputStream
output
protected boolean
paused
protected java.lang.Thread
pump
protected NonBlockingReader
reader
(package private) static int
RIGHT_ALT_PRESSED
(package private) static int
RIGHT_CTRL_PRESSED
(package private) static int
SCROLLLOCK_ON
(package private) static int
SHIFT_FLAG
(package private) static int
SHIFT_PRESSED
protected java.io.Writer
slaveInputPipe
protected Terminal.MouseTracking
tracking
static java.lang.String
TYPE_WINDOWS
static java.lang.String
TYPE_WINDOWS_256_COLOR
static java.lang.String
TYPE_WINDOWS_CONEMU
static java.lang.String
TYPE_WINDOWS_VTP
private static int
UTF8_CODE_PAGE
protected java.io.PrintWriter
writer
-
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
Constructors Constructor Description AbstractWindowsTerminal(java.io.Writer writer, java.lang.String name, java.lang.String type, java.nio.charset.Charset encoding, int codepage, boolean nativeSignals, Terminal.SignalHandler signalHandler)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description boolean
canPauseResume()
Whether this terminal supportsTerminal.pause()
andTerminal.resume()
calls.protected int
ctrl(char key)
protected void
doClose()
Attributes
getAttributes()
private static java.nio.charset.Charset
getCodepageCharset(int codepage)
protected abstract int
getConsoleMode()
protected java.lang.String
getEscapeSequence(short keyCode, int keyState)
protected java.lang.String
getRawSequence(InfoCmp.Capability cap)
Terminal.SignalHandler
handle(Terminal.Signal signal, Terminal.SignalHandler handler)
boolean
hasFocusSupport()
Returnstrue
if the terminal has support for focus tracking.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.protected abstract boolean
processConsoleInput()
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()
NonBlockingReader
reader()
Retrieve theReader
for this terminal.void
resume()
Resume reading the input stream.private static java.nio.charset.Charset
selectCharset(java.nio.charset.Charset encoding, int codepage)
void
setAttributes(Attributes attr)
protected abstract void
setConsoleMode(int mode)
void
setSize(Size size)
boolean
trackFocus(boolean tracking)
Enable or disable focus tracking mode.boolean
trackMouse(Terminal.MouseTracking tracking)
Change the mouse tracking mouse.protected void
updateConsoleMode()
java.io.PrintWriter
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 Detail
-
TYPE_WINDOWS
public static final java.lang.String TYPE_WINDOWS
- See Also:
- Constant Field Values
-
TYPE_WINDOWS_256_COLOR
public static final java.lang.String TYPE_WINDOWS_256_COLOR
- See Also:
- Constant Field Values
-
TYPE_WINDOWS_CONEMU
public static final java.lang.String TYPE_WINDOWS_CONEMU
- See Also:
- Constant Field Values
-
TYPE_WINDOWS_VTP
public static final java.lang.String TYPE_WINDOWS_VTP
- See Also:
- Constant Field Values
-
ENABLE_VIRTUAL_TERMINAL_PROCESSING
public static final int ENABLE_VIRTUAL_TERMINAL_PROCESSING
- See Also:
- Constant Field Values
-
UTF8_CODE_PAGE
private static final int UTF8_CODE_PAGE
- See Also:
- Constant Field Values
-
ENABLE_PROCESSED_INPUT
protected static final int ENABLE_PROCESSED_INPUT
- See Also:
- Constant Field Values
-
ENABLE_LINE_INPUT
protected static final int ENABLE_LINE_INPUT
- See Also:
- Constant Field Values
-
ENABLE_ECHO_INPUT
protected static final int ENABLE_ECHO_INPUT
- See Also:
- Constant Field Values
-
ENABLE_WINDOW_INPUT
protected static final int ENABLE_WINDOW_INPUT
- See Also:
- Constant Field Values
-
ENABLE_MOUSE_INPUT
protected static final int ENABLE_MOUSE_INPUT
- See Also:
- Constant Field Values
-
ENABLE_INSERT_MODE
protected static final int ENABLE_INSERT_MODE
- See Also:
- Constant Field Values
-
ENABLE_QUICK_EDIT_MODE
protected static final int ENABLE_QUICK_EDIT_MODE
- See Also:
- Constant Field Values
-
slaveInputPipe
protected final java.io.Writer slaveInputPipe
-
input
protected final NonBlockingInputStream input
-
output
protected final java.io.OutputStream output
-
reader
protected final NonBlockingReader reader
-
writer
protected final java.io.PrintWriter writer
-
nativeHandlers
protected final java.util.Map<Terminal.Signal,java.lang.Object> nativeHandlers
-
closer
protected final ShutdownHooks.Task closer
-
attributes
protected final Attributes attributes
-
originalConsoleMode
protected final int originalConsoleMode
-
lock
protected final java.lang.Object lock
-
paused
protected boolean paused
-
pump
protected java.lang.Thread pump
-
tracking
protected Terminal.MouseTracking tracking
-
focusTracking
protected boolean focusTracking
-
closing
private volatile boolean closing
-
SHIFT_FLAG
static final int SHIFT_FLAG
- See Also:
- Constant Field Values
-
ALT_FLAG
static final int ALT_FLAG
- See Also:
- Constant Field Values
-
CTRL_FLAG
static final int CTRL_FLAG
- See Also:
- Constant Field Values
-
RIGHT_ALT_PRESSED
static final int RIGHT_ALT_PRESSED
- See Also:
- Constant Field Values
-
LEFT_ALT_PRESSED
static final int LEFT_ALT_PRESSED
- See Also:
- Constant Field Values
-
RIGHT_CTRL_PRESSED
static final int RIGHT_CTRL_PRESSED
- See Also:
- Constant Field Values
-
LEFT_CTRL_PRESSED
static final int LEFT_CTRL_PRESSED
- See Also:
- Constant Field Values
-
SHIFT_PRESSED
static final int SHIFT_PRESSED
- See Also:
- Constant Field Values
-
NUMLOCK_ON
static final int NUMLOCK_ON
- See Also:
- Constant Field Values
-
SCROLLLOCK_ON
static final int SCROLLLOCK_ON
- See Also:
- Constant Field Values
-
CAPSLOCK_ON
static final int CAPSLOCK_ON
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
AbstractWindowsTerminal
public AbstractWindowsTerminal(java.io.Writer writer, java.lang.String name, java.lang.String type, java.nio.charset.Charset encoding, int codepage, boolean nativeSignals, Terminal.SignalHandler signalHandler) throws java.io.IOException
- Throws:
java.io.IOException
-
-
Method Detail
-
selectCharset
private static java.nio.charset.Charset selectCharset(java.nio.charset.Charset encoding, int codepage)
-
getCodepageCharset
private static java.nio.charset.Charset getCodepageCharset(int codepage)
-
handle
public Terminal.SignalHandler handle(Terminal.Signal signal, Terminal.SignalHandler handler)
- Specified by:
handle
in interfaceTerminal
- Overrides:
handle
in classAbstractTerminal
-
reader
public NonBlockingReader 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
public java.io.PrintWriter 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
public java.io.InputStream 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:
Terminal.reader()
-
output
public java.io.OutputStream 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:
Terminal.writer()
-
getAttributes
public Attributes getAttributes()
-
setAttributes
public void setAttributes(Attributes attr)
-
updateConsoleMode
protected void updateConsoleMode()
-
ctrl
protected int ctrl(char key)
-
setSize
public void setSize(Size size)
-
doClose
protected void doClose() throws java.io.IOException
- Overrides:
doClose
in classAbstractTerminal
- Throws:
java.io.IOException
-
processKeyEvent
protected void processKeyEvent(boolean isKeyDown, short virtualKeyCode, char ch, int controlKeyState) throws java.io.IOException
- Throws:
java.io.IOException
-
getEscapeSequence
protected java.lang.String getEscapeSequence(short keyCode, int keyState)
-
getRawSequence
protected java.lang.String getRawSequence(InfoCmp.Capability cap)
-
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:
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
- 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:
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
- Overrides:
pause
in classAbstractTerminal
- 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.- Specified by:
pause
in interfaceTerminal
- Overrides:
pause
in classAbstractTerminal
- Parameters:
wait
-true
to wait until the terminal is actually paused- Throws:
java.lang.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:
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
- Overrides:
paused
in classAbstractTerminal
- Returns:
- whether the terminal is currently reading the input stream or not
- See Also:
Terminal.pause()
,Terminal.resume()
-
pump
protected void pump()
-
processInputChar
public void processInputChar(char c) throws java.io.IOException
- Throws:
java.io.IOException
-
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
- Overrides:
trackMouse
in classAbstractTerminal
- Parameters:
tracking
- the mouse tracking mode- Returns:
true
if mouse tracking is supported
-
getConsoleMode
protected abstract int getConsoleMode()
-
setConsoleMode
protected abstract void setConsoleMode(int mode)
-
processConsoleInput
protected abstract boolean processConsoleInput() throws java.io.IOException
Read a single input event from the input buffer and process it.- Returns:
- true if new input was generated from the event
- Throws:
java.io.IOException
- if anything wrong happens
-
-