author | wetmore |
Thu, 21 Sep 2017 12:13:25 -0700 | |
changeset 47238 | 2557ac47e731 |
parent 47216 | 71c04702a3d5 |
child 50338 | 1d5694c1aa03 |
permissions | -rw-r--r-- |
31530
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
1 |
/* |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
2 |
* Copyright (c) 2002-2012, the original author or authors. |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
3 |
* |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
4 |
* This software is distributable under the BSD license. See the terms of the |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
5 |
* BSD license in the documentation provided with this software. |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
6 |
* |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
7 |
* http://www.opensource.org/licenses/bsd-license.php |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
8 |
*/ |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
9 |
package jdk.internal.jline; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
10 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
11 |
import java.io.FileDescriptor; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
12 |
import java.io.FileInputStream; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
13 |
import java.io.IOException; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
14 |
import java.io.InputStream; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
15 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
16 |
import jdk.internal.jline.internal.Configuration; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
17 |
import jdk.internal.jline.internal.Log; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
18 |
//import org.fusesource.jansi.internal.WindowsSupport; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
19 |
//import org.fusesource.jansi.internal.Kernel32; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
20 |
//import static org.fusesource.jansi.internal.Kernel32.*; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
21 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
22 |
import static jdk.internal.jline.WindowsTerminal.ConsoleMode.ENABLE_ECHO_INPUT; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
23 |
import static jdk.internal.jline.WindowsTerminal.ConsoleMode.ENABLE_LINE_INPUT; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
24 |
import static jdk.internal.jline.WindowsTerminal.ConsoleMode.ENABLE_PROCESSED_INPUT; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
25 |
import static jdk.internal.jline.WindowsTerminal.ConsoleMode.ENABLE_WINDOW_INPUT; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
26 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
27 |
/** |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
28 |
* Terminal implementation for Microsoft Windows. Terminal initialization in |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
29 |
* {@link #init} is accomplished by extracting the |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
30 |
* <em>jline_<i>version</i>.dll</em>, saving it to the system temporary |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
31 |
* directoy (determined by the setting of the <em>java.io.tmpdir</em> System |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
32 |
* property), loading the library, and then calling the Win32 APIs <a |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
33 |
* href="http://msdn.microsoft.com/library/default.asp? |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
34 |
* url=/library/en-us/dllproc/base/setconsolemode.asp">SetConsoleMode</a> and |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
35 |
* <a href="http://msdn.microsoft.com/library/default.asp? |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
36 |
* url=/library/en-us/dllproc/base/getconsolemode.asp">GetConsoleMode</a> to |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
37 |
* disable character echoing. |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
38 |
* <p/> |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
39 |
* <p> |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
40 |
* By default, the {@link #wrapInIfNeeded(java.io.InputStream)} method will attempt |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
41 |
* to test to see if the specified {@link InputStream} is {@link System#in} or a wrapper |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
42 |
* around {@link FileDescriptor#in}, and if so, will bypass the character reading to |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
43 |
* directly invoke the readc() method in the JNI library. This is so the class |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
44 |
* can read special keys (like arrow keys) which are otherwise inaccessible via |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
45 |
* the {@link System#in} stream. Using JNI reading can be bypassed by setting |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
46 |
* the <code>jline.WindowsTerminal.directConsole</code> system property |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
47 |
* to <code>false</code>. |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
48 |
* </p> |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
49 |
* |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
50 |
* @author <a href="mailto:mwp1@cornell.edu">Marc Prud'hommeaux</a> |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
51 |
* @author <a href="mailto:jason@planet57.com">Jason Dillon</a> |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
52 |
* @since 2.0 |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
53 |
*/ |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
54 |
public class WindowsTerminal |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
55 |
extends TerminalSupport |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
56 |
{ |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
57 |
public static final String DIRECT_CONSOLE = WindowsTerminal.class.getName() + ".directConsole"; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
58 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
59 |
public static final String ANSI = WindowsTerminal.class.getName() + ".ansi"; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
60 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
61 |
private boolean directConsole; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
62 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
63 |
private int originalMode; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
64 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
65 |
public WindowsTerminal() throws Exception { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
66 |
super(true); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
67 |
} |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
68 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
69 |
@Override |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
70 |
public void init() throws Exception { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
71 |
super.init(); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
72 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
73 |
// setAnsiSupported(Configuration.getBoolean(ANSI, true)); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
74 |
setAnsiSupported(false); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
75 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
76 |
// |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
77 |
// FIXME: Need a way to disable direct console and sysin detection muck |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
78 |
// |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
79 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
80 |
setDirectConsole(Configuration.getBoolean(DIRECT_CONSOLE, true)); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
81 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
82 |
this.originalMode = getConsoleMode(); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
83 |
setConsoleMode(originalMode & ~ENABLE_ECHO_INPUT.code); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
84 |
setEchoEnabled(false); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
85 |
} |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
86 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
87 |
/** |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
88 |
* Restore the original terminal configuration, which can be used when |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
89 |
* shutting down the console reader. The ConsoleReader cannot be |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
90 |
* used after calling this method. |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
91 |
*/ |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
92 |
@Override |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
93 |
public void restore() throws Exception { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
94 |
// restore the old console mode |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
95 |
setConsoleMode(originalMode); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
96 |
super.restore(); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
97 |
} |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
98 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
99 |
@Override |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
100 |
public int getWidth() { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
101 |
int w = getWindowsTerminalWidth(); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
102 |
return w < 1 ? DEFAULT_WIDTH : w; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
103 |
} |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
104 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
105 |
@Override |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
106 |
public int getHeight() { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
107 |
int h = getWindowsTerminalHeight(); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
108 |
return h < 1 ? DEFAULT_HEIGHT : h; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
109 |
} |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
110 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
111 |
@Override |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
112 |
public void setEchoEnabled(final boolean enabled) { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
113 |
// Must set these four modes at the same time to make it work fine. |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
114 |
if (enabled) { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
115 |
setConsoleMode(getConsoleMode() | |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
116 |
ENABLE_ECHO_INPUT.code | |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
117 |
ENABLE_LINE_INPUT.code | |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
118 |
ENABLE_PROCESSED_INPUT.code | |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
119 |
ENABLE_WINDOW_INPUT.code); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
120 |
} |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
121 |
else { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
122 |
setConsoleMode(getConsoleMode() & |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
123 |
~(ENABLE_LINE_INPUT.code | |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
124 |
ENABLE_ECHO_INPUT.code | |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
125 |
ENABLE_PROCESSED_INPUT.code | |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
126 |
ENABLE_WINDOW_INPUT.code)); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
127 |
} |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
128 |
super.setEchoEnabled(enabled); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
129 |
} |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
130 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
131 |
/** |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
132 |
* Whether or not to allow the use of the JNI console interaction. |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
133 |
*/ |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
134 |
public void setDirectConsole(final boolean flag) { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
135 |
this.directConsole = flag; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
136 |
Log.debug("Direct console: ", flag); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
137 |
} |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
138 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
139 |
/** |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
140 |
* Whether or not to allow the use of the JNI console interaction. |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
141 |
*/ |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
142 |
public Boolean getDirectConsole() { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
143 |
return directConsole; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
144 |
} |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
145 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
146 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
147 |
@Override |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
148 |
public InputStream wrapInIfNeeded(InputStream in) throws IOException { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
149 |
if (directConsole && isSystemIn(in)) { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
150 |
return new InputStream() { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
151 |
private byte[] buf = null; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
152 |
int bufIdx = 0; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
153 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
154 |
@Override |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
155 |
public int read() throws IOException { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
156 |
while (buf == null || bufIdx == buf.length) { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
157 |
buf = readConsoleInput(); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
158 |
bufIdx = 0; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
159 |
} |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
160 |
int c = buf[bufIdx] & 0xFF; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
161 |
bufIdx++; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
162 |
return c; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
163 |
} |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
164 |
}; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
165 |
} else { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
166 |
return super.wrapInIfNeeded(in); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
167 |
} |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
168 |
} |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
169 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
170 |
protected boolean isSystemIn(final InputStream in) throws IOException { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
171 |
if (in == null) { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
172 |
return false; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
173 |
} |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
174 |
else if (in == System.in) { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
175 |
return true; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
176 |
} |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
177 |
else if (in instanceof FileInputStream && ((FileInputStream) in).getFD() == FileDescriptor.in) { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
178 |
return true; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
179 |
} |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
180 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
181 |
return false; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
182 |
} |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
183 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
184 |
@Override |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
185 |
public String getOutputEncoding() { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
186 |
int codepage = getConsoleOutputCodepage(); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
187 |
//http://docs.oracle.com/javase/6/docs/technotes/guides/intl/encoding.doc.html |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
188 |
String charsetMS = "ms" + codepage; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
189 |
if (java.nio.charset.Charset.isSupported(charsetMS)) { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
190 |
return charsetMS; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
191 |
} |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
192 |
String charsetCP = "cp" + codepage; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
193 |
if (java.nio.charset.Charset.isSupported(charsetCP)) { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
194 |
return charsetCP; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
195 |
} |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
196 |
Log.debug("can't figure out the Java Charset of this code page (" + codepage + ")..."); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
197 |
return super.getOutputEncoding(); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
198 |
} |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
199 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
200 |
// |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
201 |
// Original code: |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
202 |
// |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
203 |
// private int getConsoleMode() { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
204 |
// return WindowsSupport.getConsoleMode(); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
205 |
// } |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
206 |
// |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
207 |
// private void setConsoleMode(int mode) { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
208 |
// WindowsSupport.setConsoleMode(mode); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
209 |
// } |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
210 |
// |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
211 |
// private byte[] readConsoleInput() { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
212 |
// // XXX does how many events to read in one call matter? |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
213 |
// INPUT_RECORD[] events = null; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
214 |
// try { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
215 |
// events = WindowsSupport.readConsoleInput(1); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
216 |
// } catch (IOException e) { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
217 |
// Log.debug("read Windows console input error: ", e); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
218 |
// } |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
219 |
// if (events == null) { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
220 |
// return new byte[0]; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
221 |
// } |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
222 |
// StringBuilder sb = new StringBuilder(); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
223 |
// for (int i = 0; i < events.length; i++ ) { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
224 |
// KEY_EVENT_RECORD keyEvent = events[i].keyEvent; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
225 |
// //Log.trace(keyEvent.keyDown? "KEY_DOWN" : "KEY_UP", "key code:", keyEvent.keyCode, "char:", (long)keyEvent.uchar); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
226 |
// if (keyEvent.keyDown) { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
227 |
// if (keyEvent.uchar > 0) { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
228 |
// // support some C1 control sequences: ALT + [@-_] (and [a-z]?) => ESC <ascii> |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
229 |
// // http://en.wikipedia.org/wiki/C0_and_C1_control_codes#C1_set |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
230 |
// final int altState = KEY_EVENT_RECORD.LEFT_ALT_PRESSED | KEY_EVENT_RECORD.RIGHT_ALT_PRESSED; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
231 |
// // Pressing "Alt Gr" is translated to Alt-Ctrl, hence it has to be checked that Ctrl is _not_ pressed, |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
232 |
// // otherwise inserting of "Alt Gr" codes on non-US keyboards would yield errors |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
233 |
// final int ctrlState = KEY_EVENT_RECORD.LEFT_CTRL_PRESSED | KEY_EVENT_RECORD.RIGHT_CTRL_PRESSED; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
234 |
// if (((keyEvent.uchar >= '@' && keyEvent.uchar <= '_') || (keyEvent.uchar >= 'a' && keyEvent.uchar <= 'z')) |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
235 |
// && ((keyEvent.controlKeyState & altState) != 0) && ((keyEvent.controlKeyState & ctrlState) == 0)) { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
236 |
// sb.append('\u001B'); // ESC |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
237 |
// } |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
238 |
// |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
239 |
// sb.append(keyEvent.uchar); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
240 |
// continue; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
241 |
// } |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
242 |
// // virtual keycodes: http://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).aspx |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
243 |
// // just add support for basic editing keys (no control state, no numpad keys) |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
244 |
// String escapeSequence = null; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
245 |
// switch (keyEvent.keyCode) { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
246 |
// case 0x21: // VK_PRIOR PageUp |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
247 |
// escapeSequence = "\u001B[5~"; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
248 |
// break; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
249 |
// case 0x22: // VK_NEXT PageDown |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
250 |
// escapeSequence = "\u001B[6~"; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
251 |
// break; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
252 |
// case 0x23: // VK_END |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
253 |
// escapeSequence = "\u001B[4~"; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
254 |
// break; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
255 |
// case 0x24: // VK_HOME |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
256 |
// escapeSequence = "\u001B[1~"; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
257 |
// break; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
258 |
// case 0x25: // VK_LEFT |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
259 |
// escapeSequence = "\u001B[D"; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
260 |
// break; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
261 |
// case 0x26: // VK_UP |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
262 |
// escapeSequence = "\u001B[A"; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
263 |
// break; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
264 |
// case 0x27: // VK_RIGHT |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
265 |
// escapeSequence = "\u001B[C"; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
266 |
// break; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
267 |
// case 0x28: // VK_DOWN |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
268 |
// escapeSequence = "\u001B[B"; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
269 |
// break; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
270 |
// case 0x2D: // VK_INSERT |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
271 |
// escapeSequence = "\u001B[2~"; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
272 |
// break; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
273 |
// case 0x2E: // VK_DELETE |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
274 |
// escapeSequence = "\u001B[3~"; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
275 |
// break; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
276 |
// default: |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
277 |
// break; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
278 |
// } |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
279 |
// if (escapeSequence != null) { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
280 |
// for (int k = 0; k < keyEvent.repeatCount; k++) { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
281 |
// sb.append(escapeSequence); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
282 |
// } |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
283 |
// } |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
284 |
// } else { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
285 |
// // key up event |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
286 |
// // support ALT+NumPad input method |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
287 |
// if (keyEvent.keyCode == 0x12/*VK_MENU ALT key*/ && keyEvent.uchar > 0) { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
288 |
// sb.append(keyEvent.uchar); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
289 |
// } |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
290 |
// } |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
291 |
// } |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
292 |
// return sb.toString().getBytes(); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
293 |
// } |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
294 |
// |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
295 |
// private int getConsoleOutputCodepage() { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
296 |
// return Kernel32.GetConsoleOutputCP(); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
297 |
// } |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
298 |
// |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
299 |
// private int getWindowsTerminalWidth() { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
300 |
// return WindowsSupport.getWindowsTerminalWidth(); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
301 |
// } |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
302 |
// |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
303 |
// private int getWindowsTerminalHeight() { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
304 |
// return WindowsSupport.getWindowsTerminalHeight(); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
305 |
// } |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
306 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
307 |
// |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
308 |
// Native Bits |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
309 |
// |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
310 |
static { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
311 |
System.loadLibrary("le"); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
312 |
initIDs(); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
313 |
} |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
314 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
315 |
private static native void initIDs(); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
316 |
|
43540
3b6ae4a56de2
8173653: jshell tool: ctrl-C when in external editor aborts jshell -- history lost
jlahoda
parents:
37813
diff
changeset
|
317 |
protected native int getConsoleMode(); |
31530
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
318 |
|
43540
3b6ae4a56de2
8173653: jshell tool: ctrl-C when in external editor aborts jshell -- history lost
jlahoda
parents:
37813
diff
changeset
|
319 |
protected native void setConsoleMode(int mode); |
31530
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
320 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
321 |
private byte[] readConsoleInput() { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
322 |
KEY_EVENT_RECORD keyEvent = readKeyEvent(); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
323 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
324 |
return convertKeys(keyEvent).getBytes(); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
325 |
} |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
326 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
327 |
public static String convertKeys(KEY_EVENT_RECORD keyEvent) { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
328 |
if (keyEvent == null) { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
329 |
return ""; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
330 |
} |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
331 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
332 |
StringBuilder sb = new StringBuilder(); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
333 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
334 |
if (keyEvent.keyDown) { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
335 |
if (keyEvent.uchar > 0) { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
336 |
// support some C1 control sequences: ALT + [@-_] (and [a-z]?) => ESC <ascii> |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
337 |
// http://en.wikipedia.org/wiki/C0_and_C1_control_codes#C1_set |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
338 |
final int altState = KEY_EVENT_RECORD.ALT_PRESSED; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
339 |
// Pressing "Alt Gr" is translated to Alt-Ctrl, hence it has to be checked that Ctrl is _not_ pressed, |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
340 |
// otherwise inserting of "Alt Gr" codes on non-US keyboards would yield errors |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
341 |
final int ctrlState = KEY_EVENT_RECORD.CTRL_PRESSED; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
342 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
343 |
boolean handled = false; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
344 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
345 |
if ((keyEvent.controlKeyState & ctrlState) != 0) { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
346 |
switch (keyEvent.keyCode) { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
347 |
case 0x43: //Ctrl-C |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
348 |
sb.append("\003"); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
349 |
handled = true; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
350 |
break; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
351 |
} |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
352 |
} |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
353 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
354 |
if ((keyEvent.controlKeyState & KEY_EVENT_RECORD.SHIFT_PRESSED) != 0) { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
355 |
switch (keyEvent.keyCode) { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
356 |
case 0x09: //Shift-Tab |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
357 |
sb.append("\033\133\132"); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
358 |
handled = true; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
359 |
break; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
360 |
} |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
361 |
} |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
362 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
363 |
if (!handled) { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
364 |
if (((keyEvent.uchar >= '@' && keyEvent.uchar <= '_') || (keyEvent.uchar >= 'a' && keyEvent.uchar <= 'z')) |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
365 |
&& ((keyEvent.controlKeyState & altState) != 0) && ((keyEvent.controlKeyState & ctrlState) == 0)) { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
366 |
sb.append('\u001B'); // ESC |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
367 |
} |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
368 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
369 |
sb.append(keyEvent.uchar); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
370 |
} |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
371 |
} else { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
372 |
// virtual keycodes: http://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).aspx |
37813
874f4ca115c3
8147984: WindowsTerminal should support function keys
jlahoda
parents:
31530
diff
changeset
|
373 |
// xterm escape codes: E. Moy, S. Gildea and T. Dickey, "XTerm Control Sequences": |
874f4ca115c3
8147984: WindowsTerminal should support function keys
jlahoda
parents:
31530
diff
changeset
|
374 |
// http://invisible-island.net/xterm/ctlseqs/ctlseqs.html |
874f4ca115c3
8147984: WindowsTerminal should support function keys
jlahoda
parents:
31530
diff
changeset
|
375 |
// http://xorg.freedesktop.org/releases/X11R6.8.1/PDF/ctlseqs.pdf |
874f4ca115c3
8147984: WindowsTerminal should support function keys
jlahoda
parents:
31530
diff
changeset
|
376 |
// just add support for basic editing keys and function keys |
31530
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
377 |
String escapeSequence = null; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
378 |
switch (keyEvent.keyCode) { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
379 |
case 0x21: // VK_PRIOR PageUp |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
380 |
escapeSequence = escapeSequence(keyEvent.controlKeyState, "\u001B[5~", "\u001B[5;%d~"); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
381 |
break; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
382 |
case 0x22: // VK_NEXT PageDown |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
383 |
escapeSequence = escapeSequence(keyEvent.controlKeyState, "\u001B[6~", "\u001B[6;%d~"); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
384 |
break; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
385 |
case 0x23: // VK_END |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
386 |
escapeSequence = escapeSequence(keyEvent.controlKeyState, "\u001B[4~", "\u001B[4;%d~"); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
387 |
break; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
388 |
case 0x24: // VK_HOME |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
389 |
escapeSequence = escapeSequence(keyEvent.controlKeyState, "\u001B[1~", "\u001B[1;%d~"); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
390 |
break; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
391 |
case 0x25: // VK_LEFT |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
392 |
escapeSequence = escapeSequence(keyEvent.controlKeyState, "\u001B[D", "\u001B[1;%dD"); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
393 |
break; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
394 |
case 0x26: // VK_UP |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
395 |
escapeSequence = escapeSequence(keyEvent.controlKeyState, "\u001B[A", "\u001B[1;%dA"); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
396 |
break; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
397 |
case 0x27: // VK_RIGHT |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
398 |
escapeSequence = escapeSequence(keyEvent.controlKeyState, "\u001B[C", "\u001B[1;%dC"); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
399 |
break; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
400 |
case 0x28: // VK_DOWN |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
401 |
escapeSequence = escapeSequence(keyEvent.controlKeyState, "\u001B[B", "\u001B[1;%dB"); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
402 |
break; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
403 |
case 0x2D: // VK_INSERT |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
404 |
escapeSequence = escapeSequence(keyEvent.controlKeyState, "\u001B[2~", "\u001B[2;%d~"); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
405 |
break; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
406 |
case 0x2E: // VK_DELETE |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
407 |
escapeSequence = escapeSequence(keyEvent.controlKeyState, "\u001B[3~", "\u001B[3;%d~"); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
408 |
break; |
37813
874f4ca115c3
8147984: WindowsTerminal should support function keys
jlahoda
parents:
31530
diff
changeset
|
409 |
case 0x70: // VK_F1 |
874f4ca115c3
8147984: WindowsTerminal should support function keys
jlahoda
parents:
31530
diff
changeset
|
410 |
escapeSequence = escapeSequence(keyEvent.controlKeyState, "\u001BOP", "\u001BO%dP"); |
874f4ca115c3
8147984: WindowsTerminal should support function keys
jlahoda
parents:
31530
diff
changeset
|
411 |
break; |
874f4ca115c3
8147984: WindowsTerminal should support function keys
jlahoda
parents:
31530
diff
changeset
|
412 |
case 0x71: // VK_F2 |
874f4ca115c3
8147984: WindowsTerminal should support function keys
jlahoda
parents:
31530
diff
changeset
|
413 |
escapeSequence = escapeSequence(keyEvent.controlKeyState, "\u001BOQ", "\u001BO%dQ"); |
874f4ca115c3
8147984: WindowsTerminal should support function keys
jlahoda
parents:
31530
diff
changeset
|
414 |
break; |
874f4ca115c3
8147984: WindowsTerminal should support function keys
jlahoda
parents:
31530
diff
changeset
|
415 |
case 0x72: // VK_F3 |
874f4ca115c3
8147984: WindowsTerminal should support function keys
jlahoda
parents:
31530
diff
changeset
|
416 |
escapeSequence = escapeSequence(keyEvent.controlKeyState, "\u001BOR", "\u001BO%dR"); |
874f4ca115c3
8147984: WindowsTerminal should support function keys
jlahoda
parents:
31530
diff
changeset
|
417 |
break; |
874f4ca115c3
8147984: WindowsTerminal should support function keys
jlahoda
parents:
31530
diff
changeset
|
418 |
case 0x73: // VK_F4 |
874f4ca115c3
8147984: WindowsTerminal should support function keys
jlahoda
parents:
31530
diff
changeset
|
419 |
escapeSequence = escapeSequence(keyEvent.controlKeyState, "\u001BOS", "\u001BO%dS"); |
874f4ca115c3
8147984: WindowsTerminal should support function keys
jlahoda
parents:
31530
diff
changeset
|
420 |
break; |
874f4ca115c3
8147984: WindowsTerminal should support function keys
jlahoda
parents:
31530
diff
changeset
|
421 |
case 0x74: // VK_F5 |
874f4ca115c3
8147984: WindowsTerminal should support function keys
jlahoda
parents:
31530
diff
changeset
|
422 |
escapeSequence = escapeSequence(keyEvent.controlKeyState, "\u001B[15~", "\u001B[15;%d~"); |
874f4ca115c3
8147984: WindowsTerminal should support function keys
jlahoda
parents:
31530
diff
changeset
|
423 |
break; |
874f4ca115c3
8147984: WindowsTerminal should support function keys
jlahoda
parents:
31530
diff
changeset
|
424 |
case 0x75: // VK_F6 |
874f4ca115c3
8147984: WindowsTerminal should support function keys
jlahoda
parents:
31530
diff
changeset
|
425 |
escapeSequence = escapeSequence(keyEvent.controlKeyState, "\u001B[17~", "\u001B[17;%d~"); |
874f4ca115c3
8147984: WindowsTerminal should support function keys
jlahoda
parents:
31530
diff
changeset
|
426 |
break; |
874f4ca115c3
8147984: WindowsTerminal should support function keys
jlahoda
parents:
31530
diff
changeset
|
427 |
case 0x76: // VK_F7 |
874f4ca115c3
8147984: WindowsTerminal should support function keys
jlahoda
parents:
31530
diff
changeset
|
428 |
escapeSequence = escapeSequence(keyEvent.controlKeyState, "\u001B[18~", "\u001B[18;%d~"); |
874f4ca115c3
8147984: WindowsTerminal should support function keys
jlahoda
parents:
31530
diff
changeset
|
429 |
break; |
874f4ca115c3
8147984: WindowsTerminal should support function keys
jlahoda
parents:
31530
diff
changeset
|
430 |
case 0x77: // VK_F8 |
874f4ca115c3
8147984: WindowsTerminal should support function keys
jlahoda
parents:
31530
diff
changeset
|
431 |
escapeSequence = escapeSequence(keyEvent.controlKeyState, "\u001B[19~", "\u001B[19;%d~"); |
874f4ca115c3
8147984: WindowsTerminal should support function keys
jlahoda
parents:
31530
diff
changeset
|
432 |
break; |
874f4ca115c3
8147984: WindowsTerminal should support function keys
jlahoda
parents:
31530
diff
changeset
|
433 |
case 0x78: // VK_F9 |
874f4ca115c3
8147984: WindowsTerminal should support function keys
jlahoda
parents:
31530
diff
changeset
|
434 |
escapeSequence = escapeSequence(keyEvent.controlKeyState, "\u001B[20~", "\u001B[20;%d~"); |
874f4ca115c3
8147984: WindowsTerminal should support function keys
jlahoda
parents:
31530
diff
changeset
|
435 |
break; |
874f4ca115c3
8147984: WindowsTerminal should support function keys
jlahoda
parents:
31530
diff
changeset
|
436 |
case 0x79: // VK_F10 |
874f4ca115c3
8147984: WindowsTerminal should support function keys
jlahoda
parents:
31530
diff
changeset
|
437 |
escapeSequence = escapeSequence(keyEvent.controlKeyState, "\u001B[21~", "\u001B[21;%d~"); |
874f4ca115c3
8147984: WindowsTerminal should support function keys
jlahoda
parents:
31530
diff
changeset
|
438 |
break; |
874f4ca115c3
8147984: WindowsTerminal should support function keys
jlahoda
parents:
31530
diff
changeset
|
439 |
case 0x7A: // VK_F11 |
874f4ca115c3
8147984: WindowsTerminal should support function keys
jlahoda
parents:
31530
diff
changeset
|
440 |
escapeSequence = escapeSequence(keyEvent.controlKeyState, "\u001B[23~", "\u001B[23;%d~"); |
874f4ca115c3
8147984: WindowsTerminal should support function keys
jlahoda
parents:
31530
diff
changeset
|
441 |
break; |
874f4ca115c3
8147984: WindowsTerminal should support function keys
jlahoda
parents:
31530
diff
changeset
|
442 |
case 0x7B: // VK_F12 |
874f4ca115c3
8147984: WindowsTerminal should support function keys
jlahoda
parents:
31530
diff
changeset
|
443 |
escapeSequence = escapeSequence(keyEvent.controlKeyState, "\u001B[24~", "\u001B[24;%d~"); |
874f4ca115c3
8147984: WindowsTerminal should support function keys
jlahoda
parents:
31530
diff
changeset
|
444 |
break; |
31530
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
445 |
default: |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
446 |
break; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
447 |
} |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
448 |
if (escapeSequence != null) { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
449 |
for (int k = 0; k < keyEvent.repeatCount; k++) { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
450 |
sb.append(escapeSequence); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
451 |
} |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
452 |
} |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
453 |
} |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
454 |
} else { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
455 |
// key up event |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
456 |
// support ALT+NumPad input method |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
457 |
if (keyEvent.keyCode == 0x12/*VK_MENU ALT key*/ && keyEvent.uchar > 0) { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
458 |
sb.append(keyEvent.uchar); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
459 |
} |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
460 |
} |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
461 |
return sb.toString(); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
462 |
} |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
463 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
464 |
private static String escapeSequence(int controlKeyState, String noControlSequence, String withControlSequence) { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
465 |
int controlNum = 1; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
466 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
467 |
if ((controlKeyState & KEY_EVENT_RECORD.SHIFT_PRESSED) != 0) { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
468 |
controlNum += 1; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
469 |
} |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
470 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
471 |
if ((controlKeyState & KEY_EVENT_RECORD.ALT_PRESSED) != 0) { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
472 |
controlNum += 2; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
473 |
} |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
474 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
475 |
if ((controlKeyState & KEY_EVENT_RECORD.CTRL_PRESSED) != 0) { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
476 |
controlNum += 4; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
477 |
} |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
478 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
479 |
if (controlNum > 1) { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
480 |
return String.format(withControlSequence, controlNum); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
481 |
} else { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
482 |
return noControlSequence; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
483 |
} |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
484 |
} |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
485 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
486 |
private native KEY_EVENT_RECORD readKeyEvent(); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
487 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
488 |
public static class KEY_EVENT_RECORD { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
489 |
public final static int ALT_PRESSED = 0x3; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
490 |
public final static int CTRL_PRESSED = 0xC; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
491 |
public final static int SHIFT_PRESSED = 0x10; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
492 |
public final boolean keyDown; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
493 |
public final char uchar; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
494 |
public final int controlKeyState; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
495 |
public final int keyCode; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
496 |
public final int repeatCount; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
497 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
498 |
public KEY_EVENT_RECORD(boolean keyDown, char uchar, int controlKeyState, int keyCode, int repeatCount) { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
499 |
this.keyDown = keyDown; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
500 |
this.uchar = uchar; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
501 |
this.controlKeyState = controlKeyState; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
502 |
this.keyCode = keyCode; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
503 |
this.repeatCount = repeatCount; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
504 |
} |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
505 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
506 |
} |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
507 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
508 |
private native int getConsoleOutputCodepage(); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
509 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
510 |
private native int getWindowsTerminalWidth(); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
511 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
512 |
private native int getWindowsTerminalHeight(); |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
513 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
514 |
/** |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
515 |
* Console mode |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
516 |
* <p/> |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
517 |
* Constants copied <tt>wincon.h</tt>. |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
518 |
*/ |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
519 |
public static enum ConsoleMode |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
520 |
{ |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
521 |
/** |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
522 |
* The ReadFile or ReadConsole function returns only when a carriage return |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
523 |
* character is read. If this mode is disable, the functions return when one |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
524 |
* or more characters are available. |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
525 |
*/ |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
526 |
ENABLE_LINE_INPUT(2), |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
527 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
528 |
/** |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
529 |
* Characters read by the ReadFile or ReadConsole function are written to |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
530 |
* the active screen buffer as they are read. This mode can be used only if |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
531 |
* the ENABLE_LINE_INPUT mode is also enabled. |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
532 |
*/ |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
533 |
ENABLE_ECHO_INPUT(4), |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
534 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
535 |
/** |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
536 |
* CTRL+C is processed by the system and is not placed in the input buffer. |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
537 |
* If the input buffer is being read by ReadFile or ReadConsole, other |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
538 |
* control keys are processed by the system and are not returned in the |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
539 |
* ReadFile or ReadConsole buffer. If the ENABLE_LINE_INPUT mode is also |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
540 |
* enabled, backspace, carriage return, and linefeed characters are handled |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
541 |
* by the system. |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
542 |
*/ |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
543 |
ENABLE_PROCESSED_INPUT(1), |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
544 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
545 |
/** |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
546 |
* User interactions that change the size of the console screen buffer are |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
547 |
* reported in the console's input buffee. Information about these events |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
548 |
* can be read from the input buffer by applications using |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
549 |
* theReadConsoleInput function, but not by those using ReadFile |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
550 |
* orReadConsole. |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
551 |
*/ |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
552 |
ENABLE_WINDOW_INPUT(8), |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
553 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
554 |
/** |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
555 |
* If the mouse pointer is within the borders of the console window and the |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
556 |
* window has the keyboard focus, mouse events generated by mouse movement |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
557 |
* and button presses are placed in the input buffer. These events are |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
558 |
* discarded by ReadFile or ReadConsole, even when this mode is enabled. |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
559 |
*/ |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
560 |
ENABLE_MOUSE_INPUT(16), |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
561 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
562 |
/** |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
563 |
* When enabled, text entered in a console window will be inserted at the |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
564 |
* current cursor location and all text following that location will not be |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
565 |
* overwritten. When disabled, all following text will be overwritten. An OR |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
566 |
* operation must be performed with this flag and the ENABLE_EXTENDED_FLAGS |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
567 |
* flag to enable this functionality. |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
568 |
*/ |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
569 |
ENABLE_PROCESSED_OUTPUT(1), |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
570 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
571 |
/** |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
572 |
* This flag enables the user to use the mouse to select and edit text. To |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
573 |
* enable this option, use the OR to combine this flag with |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
574 |
* ENABLE_EXTENDED_FLAGS. |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
575 |
*/ |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
576 |
ENABLE_WRAP_AT_EOL_OUTPUT(2),; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
577 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
578 |
public final int code; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
579 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
580 |
ConsoleMode(final int code) { |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
581 |
this.code = code; |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
582 |
} |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
583 |
} |
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
584 |
|
aa87d96a02b1
8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff
changeset
|
585 |
} |