Package jline
Class WindowsTerminal
- java.lang.Object
-
- jline.TerminalSupport
-
- jline.WindowsTerminal
-
- All Implemented Interfaces:
Terminal
- Direct Known Subclasses:
AnsiWindowsTerminal
public class WindowsTerminal extends TerminalSupport
Terminal implementation for Microsoft Windows. Terminal initialization ininit()
is accomplished by extracting the jline_version.dll, saving it to the system temporary directoy (determined by the setting of the java.io.tmpdir System property), loading the library, and then calling the Win32 APIs SetConsoleMode and GetConsoleMode to disable character echoing.By default, the
wrapInIfNeeded(java.io.InputStream)
method will attempt to test to see if the specifiedInputStream
isSystem.in
or a wrapper aroundFileDescriptor.in
, and if so, will bypass the character reading to directly invoke the readc() method in the JNI library. This is so the class can read special keys (like arrow keys) which are otherwise inaccessible via theSystem.in
stream. Using JNI reading can be bypassed by setting thejline.WindowsTerminal.directConsole
system property tofalse
.- Since:
- 2.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
WindowsTerminal.ConsoleMode
Console mode
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
ANSI
static java.lang.String
DIRECT_CONSOLE
private boolean
directConsole
private int
originalMode
-
Fields inherited from class jline.TerminalSupport
DEFAULT_HEIGHT, DEFAULT_WIDTH
-
-
Constructor Summary
Constructors Constructor Description WindowsTerminal()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
disableInterruptCharacter()
void
enableInterruptCharacter()
private static int
getConsoleMode()
private static int
getConsoleOutputCodepage()
java.lang.Boolean
getDirectConsole()
Whether or not to allow the use of the JNI console interaction.int
getHeight()
java.lang.String
getOutputEncoding()
int
getWidth()
private static int
getWindowsTerminalHeight()
private static int
getWindowsTerminalWidth()
void
init()
protected boolean
isSystemIn(java.io.InputStream in)
private byte[]
readConsoleInput()
void
restore()
Restore the original terminal configuration, which can be used when shutting down the console reader.private static void
setConsoleMode(int mode)
void
setDirectConsole(boolean flag)
Whether or not to allow the use of the JNI console interaction.void
setEchoEnabled(boolean enabled)
java.io.InputStream
wrapInIfNeeded(java.io.InputStream in)
When using native support, return the InputStream to use for reading characters else return the input stream passed as a parameter.-
Methods inherited from class jline.TerminalSupport
hasWeirdWrap, isAnsiSupported, isEchoEnabled, isSupported, reset, setAnsiSupported, wrapOutIfNeeded
-
-
-
-
Method Detail
-
init
public void init() throws java.lang.Exception
- Specified by:
init
in interfaceTerminal
- Overrides:
init
in classTerminalSupport
- Throws:
java.lang.Exception
-
restore
public void restore() throws java.lang.Exception
Restore the original terminal configuration, which can be used when shutting down the console reader. The ConsoleReader cannot be used after calling this method.- Specified by:
restore
in interfaceTerminal
- Overrides:
restore
in classTerminalSupport
- Throws:
java.lang.Exception
-
getWidth
public int getWidth()
- Specified by:
getWidth
in interfaceTerminal
- Overrides:
getWidth
in classTerminalSupport
-
getHeight
public int getHeight()
- Specified by:
getHeight
in interfaceTerminal
- Overrides:
getHeight
in classTerminalSupport
-
setEchoEnabled
public void setEchoEnabled(boolean enabled)
- Specified by:
setEchoEnabled
in interfaceTerminal
- Overrides:
setEchoEnabled
in classTerminalSupport
-
disableInterruptCharacter
public void disableInterruptCharacter()
- Specified by:
disableInterruptCharacter
in interfaceTerminal
- Overrides:
disableInterruptCharacter
in classTerminalSupport
-
enableInterruptCharacter
public void enableInterruptCharacter()
- Specified by:
enableInterruptCharacter
in interfaceTerminal
- Overrides:
enableInterruptCharacter
in classTerminalSupport
-
setDirectConsole
public void setDirectConsole(boolean flag)
Whether or not to allow the use of the JNI console interaction.
-
getDirectConsole
public java.lang.Boolean getDirectConsole()
Whether or not to allow the use of the JNI console interaction.
-
wrapInIfNeeded
public java.io.InputStream wrapInIfNeeded(java.io.InputStream in) throws java.io.IOException
Description copied from interface:Terminal
When using native support, return the InputStream to use for reading characters else return the input stream passed as a parameter.- Specified by:
wrapInIfNeeded
in interfaceTerminal
- Overrides:
wrapInIfNeeded
in classTerminalSupport
- Throws:
java.io.IOException
-
isSystemIn
protected boolean isSystemIn(java.io.InputStream in) throws java.io.IOException
- Throws:
java.io.IOException
-
getOutputEncoding
public java.lang.String getOutputEncoding()
- Specified by:
getOutputEncoding
in interfaceTerminal
- Overrides:
getOutputEncoding
in classTerminalSupport
-
getConsoleMode
private static int getConsoleMode()
-
setConsoleMode
private static void setConsoleMode(int mode)
-
readConsoleInput
private byte[] readConsoleInput()
-
getConsoleOutputCodepage
private static int getConsoleOutputCodepage()
-
getWindowsTerminalWidth
private static int getWindowsTerminalWidth()
-
getWindowsTerminalHeight
private static int getWindowsTerminalHeight()
-
-