- java.lang.Object
-
- org.jline.terminal.impl.AbstractTerminal
-
- org.jline.terminal.impl.AbstractWindowsTerminal
-
- All Implemented Interfaces:
Closeable,Flushable,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 protected Attributesattributesprotected ShutdownHooks.Taskcloserprotected static intENABLE_ECHO_INPUTprotected static intENABLE_INSERT_MODEprotected static intENABLE_LINE_INPUTprotected static intENABLE_MOUSE_INPUTprotected static intENABLE_PROCESSED_INPUTprotected static intENABLE_QUICK_EDIT_MODEstatic intENABLE_VIRTUAL_TERMINAL_PROCESSINGprotected static intENABLE_WINDOW_INPUTprotected booleanfocusTrackingprotected NonBlockingInputStreaminputprotected Objectlockprotected Map<Terminal.Signal,Object>nativeHandlersprotected intoriginalConsoleModeprotected OutputStreamoutputprotected booleanpausedprotected Threadpumpprotected NonBlockingReaderreaderprotected WriterslaveInputPipeprotected Terminal.MouseTrackingtrackingstatic StringTYPE_WINDOWSstatic StringTYPE_WINDOWS_256_COLORstatic StringTYPE_WINDOWS_CONEMUstatic StringTYPE_WINDOWS_VTPprotected PrintWriterwriter-
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(Writer writer, String name, String type, Charset encoding, int codepage, boolean nativeSignals, Terminal.SignalHandler signalHandler)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleancanPauseResume()Whether this terminal supportsTerminal.pause()andTerminal.resume()calls.protected intctrl(char key)protected voiddoClose()AttributesgetAttributes()protected abstract intgetConsoleMode()protected StringgetEscapeSequence(short keyCode, int keyState)protected StringgetRawSequence(InfoCmp.Capability cap)Terminal.SignalHandlerhandle(Terminal.Signal signal, Terminal.SignalHandler handler)booleanhasFocusSupport()Returnstrueif the terminal has support for focus tracking.InputStreaminput()Retrieve the input stream for this terminal.OutputStreamoutput()Retrieve the output stream for this terminal.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.protected abstract booleanprocessConsoleInput()Read a single input event from the input buffer and process it.voidprocessInputChar(char c)protected voidprocessKeyEvent(boolean isKeyDown, short virtualKeyCode, char ch, int controlKeyState)protected voidpump()NonBlockingReaderreader()Retrieve theReaderfor this terminal.voidresume()Resume reading the input stream.voidsetAttributes(Attributes attr)protected abstract voidsetConsoleMode(int mode)voidsetSize(Size size)booleantrackFocus(boolean tracking)Enable or disable focus tracking mode.booleantrackMouse(Terminal.MouseTracking tracking)Change the mouse tracking mouse.protected voidupdateConsoleMode()PrintWriterwriter()Retrieve theWriterfor 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 String TYPE_WINDOWS
- See Also:
- Constant Field Values
-
TYPE_WINDOWS_256_COLOR
public static final String TYPE_WINDOWS_256_COLOR
- See Also:
- Constant Field Values
-
TYPE_WINDOWS_CONEMU
public static final String TYPE_WINDOWS_CONEMU
- See Also:
- Constant Field Values
-
TYPE_WINDOWS_VTP
public static final 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
-
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 Writer slaveInputPipe
-
input
protected final NonBlockingInputStream input
-
output
protected final OutputStream output
-
reader
protected final NonBlockingReader reader
-
writer
protected final PrintWriter writer
-
nativeHandlers
protected final Map<Terminal.Signal,Object> nativeHandlers
-
closer
protected final ShutdownHooks.Task closer
-
attributes
protected final Attributes attributes
-
originalConsoleMode
protected final int originalConsoleMode
-
lock
protected final Object lock
-
paused
protected boolean paused
-
pump
protected Thread pump
-
tracking
protected Terminal.MouseTracking tracking
-
focusTracking
protected boolean focusTracking
-
-
Constructor Detail
-
AbstractWindowsTerminal
public AbstractWindowsTerminal(Writer writer, String name, String type, Charset encoding, int codepage, boolean nativeSignals, Terminal.SignalHandler signalHandler) throws IOException
- Throws:
IOException
-
-
Method Detail
-
handle
public Terminal.SignalHandler handle(Terminal.Signal signal, Terminal.SignalHandler handler)
- Specified by:
handlein interfaceTerminal- Overrides:
handlein classAbstractTerminal
-
reader
public NonBlockingReader reader()
Description copied from interface:TerminalRetrieve theReaderfor 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 PrintWriter writer()
Description copied from interface:TerminalRetrieve theWriterfor this terminal. This is the standard way to write to this terminal.- Returns:
- The writer
-
input
public InputStream input()
Description copied from interface:TerminalRetrieve 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 OutputStream output()
Description copied from interface:TerminalRetrieve 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 IOException- Overrides:
doClosein classAbstractTerminal- Throws:
IOException
-
processKeyEvent
protected void processKeyEvent(boolean isKeyDown, short virtualKeyCode, char ch, int controlKeyState) throws IOException- Throws:
IOException
-
getEscapeSequence
protected String getEscapeSequence(short keyCode, int keyState)
-
getRawSequence
protected String getRawSequence(InfoCmp.Capability cap)
-
hasFocusSupport
public boolean hasFocusSupport()
Description copied from interface:TerminalReturnstrueif the terminal has support for focus tracking.- Specified by:
hasFocusSupportin interfaceTerminal- Overrides:
hasFocusSupportin 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: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- Overrides:
trackFocusin classAbstractTerminal- Parameters:
tracking- whether the focus tracking mode should be enabled or not- Returns:
trueif focus tracking is supported
-
canPauseResume
public boolean canPauseResume()
Description copied from interface:TerminalWhether this terminal supportsTerminal.pause()andTerminal.resume()calls.- Specified by:
canPauseResumein interfaceTerminal- Overrides:
canPauseResumein 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:TerminalStop reading the input stream.- Specified by:
pausein interfaceTerminal- Overrides:
pausein classAbstractTerminal- 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- Overrides:
pausein classAbstractTerminal- 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- Overrides:
resumein classAbstractTerminal- 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- Overrides:
pausedin 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 IOException- Throws:
IOException
-
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- Overrides:
trackMousein classAbstractTerminal- Parameters:
tracking- the mouse tracking mode- Returns:
trueif mouse tracking is supported
-
getConsoleMode
protected abstract int getConsoleMode()
-
setConsoleMode
protected abstract void setConsoleMode(int mode)
-
processConsoleInput
protected abstract boolean processConsoleInput() throws IOExceptionRead 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
-
-