--- old/make/CompileJavaModules.gmk 2015-06-18 03:05:49.811135259 -0700 +++ new/make/CompileJavaModules.gmk 2015-06-18 03:05:49.648134080 -0700 @@ -376,6 +376,10 @@ ################################################################################ +jdk.jline_COPY := .properties + +################################################################################ + jdk.rmic_SETUP := GENERATE_JDKBYTECODE_NOWARNINGS jdk.rmic_CLEAN := .properties --- old/make/Images.gmk 2015-06-18 03:05:50.890143064 -0700 +++ new/make/Images.gmk 2015-06-18 03:05:50.815142522 -0700 @@ -41,7 +41,7 @@ jdk.security.auth jdk.security.jgss jdk.pack200 jdk.xml.dom # providers -PROVIDER_MODULES += jdk.charsets jdk.crypto.ec jdk.crypto.pkcs11 jdk.jvmstat jdk.localedata \ +PROVIDER_MODULES += jdk.charsets jdk.crypto.ec jdk.crypto.pkcs11 jdk.jline jdk.jvmstat jdk.localedata \ jdk.naming.dns jdk.naming.rmi jdk.scripting.nashorn jdk.zipfs # tools --- old/./modules.xml 2015-06-18 03:05:51.365146500 -0700 +++ new/./modules.xml 2015-06-18 03:05:51.270145812 -0700 @@ -1703,6 +1703,28 @@ java.base + jdk.jline + java.base + java.desktop + java.datatransfer + + jdk.internal.jline + jdk.scripting.nashorn + + + jdk.internal.jline.console + jdk.scripting.nashorn + + + jdk.internal.jline.console.completer + jdk.scripting.nashorn + + + jdk.internal.jline.console.history + jdk.scripting.nashorn + + + jdk.jvmstat java.base java.rmi --- old/jdk/make/src/classes/build/tools/module/ext.modules 2015-06-18 03:05:51.962150818 -0700 +++ new/jdk/make/src/classes/build/tools/module/ext.modules 2015-06-18 03:05:51.775149466 -0700 @@ -9,6 +9,7 @@ jdk.crypto.mscapi jdk.crypto.pkcs11 jdk.crypto.ucrypto +jdk.jline jdk.localedata jdk.naming.dns jdk.scripting.nashorn --- old/jdk/src/jdk.jline/share/classes/jdk/internal/jline/NoInterruptUnixTerminal.java 2015-06-18 03:05:52.641155730 -0700 +++ new/jdk/src/jdk.jline/share/classes/jdk/internal/jline/NoInterruptUnixTerminal.java 2015-06-18 03:05:52.457154400 -0700 @@ -6,7 +6,7 @@ * * http://www.opensource.org/licenses/bsd-license.php */ -package jline; +package jdk.internal.jline; // Based on Apache Karaf impl --- old/jdk/src/jdk.jline/share/classes/jdk/internal/jline/Terminal.java 2015-06-18 03:05:53.352160873 -0700 +++ new/jdk/src/jdk.jline/share/classes/jdk/internal/jline/Terminal.java 2015-06-18 03:05:53.137159319 -0700 @@ -6,7 +6,7 @@ * * http://www.opensource.org/licenses/bsd-license.php */ -package jline; +package jdk.internal.jline; import java.io.IOException; import java.io.InputStream; --- old/jdk/src/jdk.jline/share/classes/jdk/internal/jline/TerminalFactory.java 2015-06-18 03:05:54.045165886 -0700 +++ new/jdk/src/jdk.jline/share/classes/jdk/internal/jline/TerminalFactory.java 2015-06-18 03:05:53.831164338 -0700 @@ -6,17 +6,16 @@ * * http://www.opensource.org/licenses/bsd-license.php */ -package jline; +package jdk.internal.jline; import java.text.MessageFormat; import java.util.HashMap; import java.util.Map; -import jline.internal.Configuration; -import jline.internal.Log; -import jline.internal.Preconditions; - -import static jline.internal.Preconditions.checkNotNull; +import jdk.internal.jline.internal.Configuration; +import jdk.internal.jline.internal.Log; +import jdk.internal.jline.internal.Preconditions; +import static jdk.internal.jline.internal.Preconditions.checkNotNull; /** * Creates terminal instances. @@ -149,7 +148,8 @@ private static final Map> FLAVORS = new HashMap>(); static { - registerFlavor(Flavor.WINDOWS, AnsiWindowsTerminal.class); +// registerFlavor(Flavor.WINDOWS, AnsiWindowsTerminal.class); + registerFlavor(Flavor.WINDOWS, WindowsTerminal.class); registerFlavor(Flavor.UNIX, UnixTerminal.class); } --- old/jdk/src/jdk.jline/share/classes/jdk/internal/jline/TerminalSupport.java 2015-06-18 03:05:54.786171247 -0700 +++ new/jdk/src/jdk.jline/share/classes/jdk/internal/jline/TerminalSupport.java 2015-06-18 03:05:54.552169554 -0700 @@ -6,15 +6,15 @@ * * http://www.opensource.org/licenses/bsd-license.php */ -package jline; +package jdk.internal.jline; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import jline.internal.Log; -import jline.internal.ShutdownHooks; -import jline.internal.ShutdownHooks.Task; +import jdk.internal.jline.internal.Log; +import jdk.internal.jline.internal.ShutdownHooks; +import jdk.internal.jline.internal.ShutdownHooks.Task; /** * Provides support for {@link Terminal} instances. --- old/jdk/src/jdk.jline/share/classes/jdk/internal/jline/UnixTerminal.java 2015-06-18 03:05:56.103180773 -0700 +++ new/jdk/src/jdk.jline/share/classes/jdk/internal/jline/UnixTerminal.java 2015-06-18 03:05:55.570176918 -0700 @@ -6,10 +6,10 @@ * * http://www.opensource.org/licenses/bsd-license.php */ -package jline; +package jdk.internal.jline; -import jline.internal.Log; -import jline.internal.TerminalLineSettings; +import jdk.internal.jline.internal.Log; +import jdk.internal.jline.internal.TerminalLineSettings; /** * Terminal that is used for unix platforms. Terminal initialization @@ -22,7 +22,7 @@ * @author Marc Prud'hommeaux * @author Dale Kemp * @author Jason Dillon - * @author Jean-Baptiste Onofré + * @author Jean-Baptiste Onofr\u00E9 * @since 2.0 */ public class UnixTerminal --- old/jdk/src/jdk.jline/share/classes/jdk/internal/jline/UnsupportedTerminal.java 2015-06-18 03:05:57.276189259 -0700 +++ new/jdk/src/jdk.jline/share/classes/jdk/internal/jline/UnsupportedTerminal.java 2015-06-18 03:05:56.983187140 -0700 @@ -6,7 +6,7 @@ * * http://www.opensource.org/licenses/bsd-license.php */ -package jline; +package jdk.internal.jline; /** * An unsupported terminal. --- old/jdk/src/jdk.jline/share/classes/jdk/internal/jline/WindowsTerminal.java 2015-06-18 03:05:57.977194329 -0700 +++ new/jdk/src/jdk.jline/share/classes/jdk/internal/jline/WindowsTerminal.java 2015-06-18 03:05:57.813193143 -0700 @@ -6,24 +6,23 @@ * * http://www.opensource.org/licenses/bsd-license.php */ -package jline; +package jdk.internal.jline; import java.io.FileDescriptor; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; -import jline.internal.Configuration; -import jline.internal.Log; -import org.fusesource.jansi.internal.WindowsSupport; -import org.fusesource.jansi.internal.Kernel32; -import static org.fusesource.jansi.internal.Kernel32.*; - -import static jline.WindowsTerminal.ConsoleMode.ENABLE_ECHO_INPUT; -import static jline.WindowsTerminal.ConsoleMode.ENABLE_LINE_INPUT; -import static jline.WindowsTerminal.ConsoleMode.ENABLE_PROCESSED_INPUT; -import static jline.WindowsTerminal.ConsoleMode.ENABLE_WINDOW_INPUT; -import static jline.internal.Preconditions.checkNotNull; +import jdk.internal.jline.internal.Configuration; +import jdk.internal.jline.internal.Log; +//import org.fusesource.jansi.internal.WindowsSupport; +//import org.fusesource.jansi.internal.Kernel32; +//import static org.fusesource.jansi.internal.Kernel32.*; + +import static jdk.internal.jline.WindowsTerminal.ConsoleMode.ENABLE_ECHO_INPUT; +import static jdk.internal.jline.WindowsTerminal.ConsoleMode.ENABLE_LINE_INPUT; +import static jdk.internal.jline.WindowsTerminal.ConsoleMode.ENABLE_PROCESSED_INPUT; +import static jdk.internal.jline.WindowsTerminal.ConsoleMode.ENABLE_WINDOW_INPUT; /** * Terminal implementation for Microsoft Windows. Terminal initialization in @@ -65,13 +64,15 @@ public WindowsTerminal() throws Exception { super(true); + System.loadLibrary("jline"); } @Override public void init() throws Exception { super.init(); - setAnsiSupported(Configuration.getBoolean(ANSI, true)); +// setAnsiSupported(Configuration.getBoolean(ANSI, true)); + setAnsiSupported(false); // // FIXME: Need a way to disable direct console and sysin detection muck @@ -198,80 +199,203 @@ } // + // Original code: + // +// private int getConsoleMode() { +// return WindowsSupport.getConsoleMode(); +// } +// +// private void setConsoleMode(int mode) { +// WindowsSupport.setConsoleMode(mode); +// } +// +// private byte[] readConsoleInput() { +// // XXX does how many events to read in one call matter? +// INPUT_RECORD[] events = null; +// try { +// events = WindowsSupport.readConsoleInput(1); +// } catch (IOException e) { +// Log.debug("read Windows console input error: ", e); +// } +// if (events == null) { +// return new byte[0]; +// } +// StringBuilder sb = new StringBuilder(); +// for (int i = 0; i < events.length; i++ ) { +// KEY_EVENT_RECORD keyEvent = events[i].keyEvent; +// //Log.trace(keyEvent.keyDown? "KEY_DOWN" : "KEY_UP", "key code:", keyEvent.keyCode, "char:", (long)keyEvent.uchar); +// if (keyEvent.keyDown) { +// if (keyEvent.uchar > 0) { +// // support some C1 control sequences: ALT + [@-_] (and [a-z]?) => ESC +// // http://en.wikipedia.org/wiki/C0_and_C1_control_codes#C1_set +// final int altState = KEY_EVENT_RECORD.LEFT_ALT_PRESSED | KEY_EVENT_RECORD.RIGHT_ALT_PRESSED; +// // Pressing "Alt Gr" is translated to Alt-Ctrl, hence it has to be checked that Ctrl is _not_ pressed, +// // otherwise inserting of "Alt Gr" codes on non-US keyboards would yield errors +// final int ctrlState = KEY_EVENT_RECORD.LEFT_CTRL_PRESSED | KEY_EVENT_RECORD.RIGHT_CTRL_PRESSED; +// if (((keyEvent.uchar >= '@' && keyEvent.uchar <= '_') || (keyEvent.uchar >= 'a' && keyEvent.uchar <= 'z')) +// && ((keyEvent.controlKeyState & altState) != 0) && ((keyEvent.controlKeyState & ctrlState) == 0)) { +// sb.append('\u001B'); // ESC +// } +// +// sb.append(keyEvent.uchar); +// continue; +// } +// // virtual keycodes: http://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).aspx +// // just add support for basic editing keys (no control state, no numpad keys) +// String escapeSequence = null; +// switch (keyEvent.keyCode) { +// case 0x21: // VK_PRIOR PageUp +// escapeSequence = "\u001B[5~"; +// break; +// case 0x22: // VK_NEXT PageDown +// escapeSequence = "\u001B[6~"; +// break; +// case 0x23: // VK_END +// escapeSequence = "\u001B[4~"; +// break; +// case 0x24: // VK_HOME +// escapeSequence = "\u001B[1~"; +// break; +// case 0x25: // VK_LEFT +// escapeSequence = "\u001B[D"; +// break; +// case 0x26: // VK_UP +// escapeSequence = "\u001B[A"; +// break; +// case 0x27: // VK_RIGHT +// escapeSequence = "\u001B[C"; +// break; +// case 0x28: // VK_DOWN +// escapeSequence = "\u001B[B"; +// break; +// case 0x2D: // VK_INSERT +// escapeSequence = "\u001B[2~"; +// break; +// case 0x2E: // VK_DELETE +// escapeSequence = "\u001B[3~"; +// break; +// default: +// break; +// } +// if (escapeSequence != null) { +// for (int k = 0; k < keyEvent.repeatCount; k++) { +// sb.append(escapeSequence); +// } +// } +// } else { +// // key up event +// // support ALT+NumPad input method +// if (keyEvent.keyCode == 0x12/*VK_MENU ALT key*/ && keyEvent.uchar > 0) { +// sb.append(keyEvent.uchar); +// } +// } +// } +// return sb.toString().getBytes(); +// } +// +// private int getConsoleOutputCodepage() { +// return Kernel32.GetConsoleOutputCP(); +// } +// +// private int getWindowsTerminalWidth() { +// return WindowsSupport.getWindowsTerminalWidth(); +// } +// +// private int getWindowsTerminalHeight() { +// return WindowsSupport.getWindowsTerminalHeight(); +// } + + // // Native Bits // - private int getConsoleMode() { - return WindowsSupport.getConsoleMode(); - } + private native int getConsoleMode(); - private void setConsoleMode(int mode) { - WindowsSupport.setConsoleMode(mode); - } + private native void setConsoleMode(int mode); private byte[] readConsoleInput() { - // XXX does how many events to read in one call matter? - INPUT_RECORD[] events = null; - try { - events = WindowsSupport.readConsoleInput(1); - } catch (IOException e) { - Log.debug("read Windows console input error: ", e); - } - if (events == null) { - return new byte[0]; + KEY_EVENT_RECORD keyEvent = readKeyEvent(); + + return convertKeys(keyEvent).getBytes(); + } + + public static String convertKeys(KEY_EVENT_RECORD keyEvent) { + if (keyEvent == null) { + return ""; } + StringBuilder sb = new StringBuilder(); - for (int i = 0; i < events.length; i++ ) { - KEY_EVENT_RECORD keyEvent = events[i].keyEvent; - //Log.trace(keyEvent.keyDown? "KEY_DOWN" : "KEY_UP", "key code:", keyEvent.keyCode, "char:", (long)keyEvent.uchar); - if (keyEvent.keyDown) { - if (keyEvent.uchar > 0) { - // support some C1 control sequences: ALT + [@-_] (and [a-z]?) => ESC - // http://en.wikipedia.org/wiki/C0_and_C1_control_codes#C1_set - final int altState = KEY_EVENT_RECORD.LEFT_ALT_PRESSED | KEY_EVENT_RECORD.RIGHT_ALT_PRESSED; - // Pressing "Alt Gr" is translated to Alt-Ctrl, hence it has to be checked that Ctrl is _not_ pressed, - // otherwise inserting of "Alt Gr" codes on non-US keyboards would yield errors - final int ctrlState = KEY_EVENT_RECORD.LEFT_CTRL_PRESSED | KEY_EVENT_RECORD.RIGHT_CTRL_PRESSED; + + if (keyEvent.keyDown) { + if (keyEvent.uchar > 0) { + // support some C1 control sequences: ALT + [@-_] (and [a-z]?) => ESC + // http://en.wikipedia.org/wiki/C0_and_C1_control_codes#C1_set + final int altState = KEY_EVENT_RECORD.ALT_PRESSED; + // Pressing "Alt Gr" is translated to Alt-Ctrl, hence it has to be checked that Ctrl is _not_ pressed, + // otherwise inserting of "Alt Gr" codes on non-US keyboards would yield errors + final int ctrlState = KEY_EVENT_RECORD.CTRL_PRESSED; + + boolean handled = false; + + if ((keyEvent.controlKeyState & ctrlState) != 0) { + switch (keyEvent.keyCode) { + case 0x43: //Ctrl-C + sb.append("\003"); + handled = true; + break; + } + } + + if ((keyEvent.controlKeyState & KEY_EVENT_RECORD.SHIFT_PRESSED) != 0) { + switch (keyEvent.keyCode) { + case 0x09: //Shift-Tab + sb.append("\033\133\132"); + handled = true; + break; + } + } + + if (!handled) { if (((keyEvent.uchar >= '@' && keyEvent.uchar <= '_') || (keyEvent.uchar >= 'a' && keyEvent.uchar <= 'z')) && ((keyEvent.controlKeyState & altState) != 0) && ((keyEvent.controlKeyState & ctrlState) == 0)) { sb.append('\u001B'); // ESC } sb.append(keyEvent.uchar); - continue; } + } else { // virtual keycodes: http://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).aspx // just add support for basic editing keys (no control state, no numpad keys) String escapeSequence = null; switch (keyEvent.keyCode) { case 0x21: // VK_PRIOR PageUp - escapeSequence = "\u001B[5~"; + escapeSequence = escapeSequence(keyEvent.controlKeyState, "\u001B[5~", "\u001B[5;%d~"); break; case 0x22: // VK_NEXT PageDown - escapeSequence = "\u001B[6~"; + escapeSequence = escapeSequence(keyEvent.controlKeyState, "\u001B[6~", "\u001B[6;%d~"); break; case 0x23: // VK_END - escapeSequence = "\u001B[4~"; + escapeSequence = escapeSequence(keyEvent.controlKeyState, "\u001B[4~", "\u001B[4;%d~"); break; case 0x24: // VK_HOME - escapeSequence = "\u001B[1~"; + escapeSequence = escapeSequence(keyEvent.controlKeyState, "\u001B[1~", "\u001B[1;%d~"); break; case 0x25: // VK_LEFT - escapeSequence = "\u001B[D"; + escapeSequence = escapeSequence(keyEvent.controlKeyState, "\u001B[D", "\u001B[1;%dD"); break; case 0x26: // VK_UP - escapeSequence = "\u001B[A"; + escapeSequence = escapeSequence(keyEvent.controlKeyState, "\u001B[A", "\u001B[1;%dA"); break; case 0x27: // VK_RIGHT - escapeSequence = "\u001B[C"; + escapeSequence = escapeSequence(keyEvent.controlKeyState, "\u001B[C", "\u001B[1;%dC"); break; case 0x28: // VK_DOWN - escapeSequence = "\u001B[B"; + escapeSequence = escapeSequence(keyEvent.controlKeyState, "\u001B[B", "\u001B[1;%dB"); break; case 0x2D: // VK_INSERT - escapeSequence = "\u001B[2~"; + escapeSequence = escapeSequence(keyEvent.controlKeyState, "\u001B[2~", "\u001B[2;%d~"); break; case 0x2E: // VK_DELETE - escapeSequence = "\u001B[3~"; + escapeSequence = escapeSequence(keyEvent.controlKeyState, "\u001B[3~", "\u001B[3;%d~"); break; default: break; @@ -281,29 +405,67 @@ sb.append(escapeSequence); } } - } else { - // key up event - // support ALT+NumPad input method - if (keyEvent.keyCode == 0x12/*VK_MENU ALT key*/ && keyEvent.uchar > 0) { - sb.append(keyEvent.uchar); - } + } + } else { + // key up event + // support ALT+NumPad input method + if (keyEvent.keyCode == 0x12/*VK_MENU ALT key*/ && keyEvent.uchar > 0) { + sb.append(keyEvent.uchar); } } - return sb.toString().getBytes(); + return sb.toString(); } - private int getConsoleOutputCodepage() { - return Kernel32.GetConsoleOutputCP(); - } + private static String escapeSequence(int controlKeyState, String noControlSequence, String withControlSequence) { + int controlNum = 1; + + if ((controlKeyState & KEY_EVENT_RECORD.SHIFT_PRESSED) != 0) { + controlNum += 1; + } + + if ((controlKeyState & KEY_EVENT_RECORD.ALT_PRESSED) != 0) { + controlNum += 2; + } + + if ((controlKeyState & KEY_EVENT_RECORD.CTRL_PRESSED) != 0) { + controlNum += 4; + } - private int getWindowsTerminalWidth() { - return WindowsSupport.getWindowsTerminalWidth(); + if (controlNum > 1) { + return String.format(withControlSequence, controlNum); + } else { + return noControlSequence; + } } - private int getWindowsTerminalHeight() { - return WindowsSupport.getWindowsTerminalHeight(); + private native KEY_EVENT_RECORD readKeyEvent(); + + public static class KEY_EVENT_RECORD { + public final static int ALT_PRESSED = 0x3; + public final static int CTRL_PRESSED = 0xC; + public final static int SHIFT_PRESSED = 0x10; + public final boolean keyDown; + public final char uchar; + public final int controlKeyState; + public final int keyCode; + public final int repeatCount; + + public KEY_EVENT_RECORD(boolean keyDown, char uchar, int controlKeyState, int keyCode, int repeatCount) { + this.keyDown = keyDown; + this.uchar = uchar; + this.controlKeyState = controlKeyState; + this.keyCode = keyCode; + this.repeatCount = repeatCount; + } + } + private native int getConsoleOutputCodepage(); + + private native int getWindowsTerminalWidth(); + + private native int getWindowsTerminalHeight(); + /** * Console mode *

--- old/jdk/src/jdk.jline/share/classes/jdk/internal/jline/console/ConsoleKeys.java 2015-06-18 03:05:58.575198656 -0700 +++ new/jdk/src/jdk.jline/share/classes/jdk/internal/jline/console/ConsoleKeys.java 2015-06-18 03:05:58.415197498 -0700 @@ -6,7 +6,7 @@ * * http://www.opensource.org/licenses/bsd-license.php */ -package jline.console; +package jdk.internal.jline.console; import java.io.BufferedReader; import java.io.File; @@ -18,10 +18,10 @@ import java.util.List; import java.util.Map; -import jline.internal.Log; +import jdk.internal.jline.internal.Log; /** - * @author Ståle W. Pedersen + * @author St\u00E5le W. Pedersen */ public class ConsoleKeys { --- old/jdk/src/jdk.jline/share/classes/jdk/internal/jline/console/ConsoleReader.java 2015-06-18 03:05:59.223203343 -0700 +++ new/jdk/src/jdk.jline/share/classes/jdk/internal/jline/console/ConsoleReader.java 2015-06-18 03:05:59.053202113 -0700 @@ -6,7 +6,7 @@ * * http://www.opensource.org/licenses/bsd-license.php */ -package jline.console; +package jdk.internal.jline.console; import java.awt.*; import java.awt.datatransfer.Clipboard; @@ -37,24 +37,25 @@ import java.util.Map; import java.util.ResourceBundle; import java.util.Stack; +import java.util.regex.Pattern; -import jline.Terminal; -import jline.TerminalFactory; -import jline.UnixTerminal; -import jline.console.completer.CandidateListCompletionHandler; -import jline.console.completer.Completer; -import jline.console.completer.CompletionHandler; -import jline.console.history.History; -import jline.console.history.MemoryHistory; -import jline.internal.Configuration; -import jline.internal.InputStreamReader; -import jline.internal.Log; -import jline.internal.NonBlockingInputStream; -import jline.internal.Nullable; -import jline.internal.Urls; -import org.fusesource.jansi.AnsiOutputStream; +import jdk.internal.jline.Terminal; +import jdk.internal.jline.TerminalFactory; +import jdk.internal.jline.UnixTerminal; +import jdk.internal.jline.console.completer.CandidateListCompletionHandler; +import jdk.internal.jline.console.completer.Completer; +import jdk.internal.jline.console.completer.CompletionHandler; +import jdk.internal.jline.console.history.History; +import jdk.internal.jline.console.history.MemoryHistory; +import jdk.internal.jline.internal.Configuration; +import jdk.internal.jline.internal.InputStreamReader; +import jdk.internal.jline.internal.Log; +import jdk.internal.jline.internal.NonBlockingInputStream; +import jdk.internal.jline.internal.Nullable; +import jdk.internal.jline.internal.Urls; +//import org.fusesource.jansi.AnsiOutputStream; -import static jline.internal.Preconditions.checkNotNull; +import static jdk.internal.jline.internal.Preconditions.checkNotNull; /** * A reader for console applications. It supports custom tab-completion, @@ -515,18 +516,21 @@ return str; } - private String stripAnsi(String str) { + String stripAnsi(String str) { if (str == null) return ""; - try { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - AnsiOutputStream aos = new AnsiOutputStream(baos); - aos.write(str.getBytes()); - aos.flush(); - return baos.toString(); - } catch (IOException e) { - return str; - } + return ANSI_CODE_PATTERN.matcher(str).replaceAll(""); +// try { +// ByteArrayOutputStream baos = new ByteArrayOutputStream(); +// AnsiOutputStream aos = new AnsiOutputStream(baos); +// aos.write(str.getBytes()); +// aos.flush(); +// return baos.toString(); +// } catch (IOException e) { +// return str; +// } } + //where: + private static final Pattern ANSI_CODE_PATTERN = Pattern.compile("\033\\[[^@-~]*[@-~]"); /** * Move the cursor position to the specified absolute index. @@ -665,6 +669,7 @@ * Expand event designator such as !!, !#, !3, etc... * See http://www.gnu.org/software/bash/manual/html_node/Event-Designators.html */ + @SuppressWarnings("fallthrough") protected String expandEvents(String str) throws IOException { StringBuilder sb = new StringBuilder(); for (int i = 0; i < str.length(); i++) { @@ -1217,7 +1222,7 @@ * @param startPos The start position * @param endPos The end position. * @param isChange If true, then the delete is part of a change operationg - * (e.g. "c$" is change-to-end-of line, so we first must delete to end + * (e.g. "c$" is change-to-end-of line, so we first must delete to end * of line to start the change * @return true if it succeeded, false otherwise * @throws IOException @@ -1237,7 +1242,7 @@ buf.cursor = startPos; buf.buffer.delete(startPos, endPos); drawBuffer(endPos - startPos); - + // If we are doing a delete operation (e.g. "d$") then don't leave the // cursor dangling off the end. In reality the "isChange" flag is silly // what is really happening is that if we are in "move-mode" then the @@ -1367,7 +1372,7 @@ while (count-- > 0) { int pos = buf.cursor + 1; while (pos < buf.buffer.length()) { - if (buf.buffer.charAt(pos) == (char) searchChar) { + if (buf.buffer.charAt(pos) == searchChar) { setCursorPosition(pos); ok = true; break; @@ -1395,7 +1400,7 @@ while (count-- > 0) { int pos = buf.cursor - 1; while (pos >= 0) { - if (buf.buffer.charAt(pos) == (char) searchChar) { + if (buf.buffer.charAt(pos) == searchChar) { setCursorPosition(pos); ok = true; break; @@ -1610,6 +1615,7 @@ * Implements vi search ("/" or "?"). * @throws IOException */ + @SuppressWarnings("fallthrough") private int viSearch(char searchChar) throws IOException { boolean isForward = (searchChar == '/'); @@ -2909,7 +2915,7 @@ * only move on an expclit entry to movement * mode. */ - if (state == state.NORMAL) { + if (state == State.NORMAL) { moveCursor(-1); } consoleKeys.setKeyMap(KeyMap.VI_MOVE); @@ -3054,7 +3060,7 @@ state = State.VI_CHANGE_TO; } break; - + case VI_KILL_WHOLE_LINE: success = setCursorPosition(0) && killLine(); consoleKeys.setKeyMap(KeyMap.VI_INSERT); @@ -3086,11 +3092,11 @@ ? readCharacter() : pushBackChar.pop()); break; - + case VI_DELETE_TO_EOL: success = viDeleteTo(buf.cursor, buf.buffer.length(), false); break; - + case VI_CHANGE_TO_EOL: success = viDeleteTo(buf.cursor, buf.buffer.length(), true); consoleKeys.setKeyMap(KeyMap.VI_INSERT); @@ -3600,6 +3606,7 @@ } try { + @SuppressWarnings("deprecation") Object content = transferable.getTransferData(DataFlavor.plainTextFlavor); // This fix was suggested in bug #1060649 at --- old/jdk/src/jdk.jline/share/classes/jdk/internal/jline/console/CursorBuffer.java 2015-06-18 03:05:59.841207813 -0700 +++ new/jdk/src/jdk.jline/share/classes/jdk/internal/jline/console/CursorBuffer.java 2015-06-18 03:05:59.687206698 -0700 @@ -6,9 +6,9 @@ * * http://www.opensource.org/licenses/bsd-license.php */ -package jline.console; +package jdk.internal.jline.console; -import static jline.internal.Preconditions.checkNotNull; +import static jdk.internal.jline.internal.Preconditions.checkNotNull; /** * A holder for a {@link StringBuilder} that also contains the current cursor position. @@ -24,13 +24,13 @@ public int cursor = 0; public final StringBuilder buffer = new StringBuilder(); - + public CursorBuffer copy () { CursorBuffer that = new CursorBuffer(); that.overTyping = this.overTyping; that.cursor = this.cursor; that.buffer.append (this.toString()); - + return that; } --- old/jdk/src/jdk.jline/share/classes/jdk/internal/jline/console/KeyMap.java 2015-06-18 03:06:00.569213079 -0700 +++ new/jdk/src/jdk.jline/share/classes/jdk/internal/jline/console/KeyMap.java 2015-06-18 03:06:00.357211545 -0700 @@ -6,7 +6,7 @@ * * http://www.opensource.org/licenses/bsd-license.php */ -package jline.console; +package jdk.internal.jline.console; import java.util.HashMap; import java.util.Map; @@ -18,7 +18,7 @@ * @since 2.6 */ public class KeyMap { - + public static final String VI_MOVE = "vi-move"; public static final String VI_INSERT = "vi-insert"; public static final String EMACS = "emacs"; @@ -34,7 +34,7 @@ private Object anotherKey = null; private String name; private boolean isViKeyMap; - + public KeyMap(String name, boolean isViKeyMap) { this(name, new Object[KEYMAP_LENGTH], isViKeyMap); } @@ -44,11 +44,11 @@ this.name = name; this.isViKeyMap = isViKeyMap; } - + public boolean isViKeyMap() { return isViKeyMap; } - + public String getName() { return name; } @@ -85,21 +85,21 @@ } public void bindIfNotBound( CharSequence keySeq, Object function ) { - + bind (this, keySeq, function, true); } - + public void bind( CharSequence keySeq, Object function ) { - + bind (this, keySeq, function, false); } - + private static void bind( KeyMap map, CharSequence keySeq, Object function ) { - + bind (map, keySeq, function, false); } - - private static void bind( KeyMap map, CharSequence keySeq, Object function, + + private static void bind( KeyMap map, CharSequence keySeq, Object function, boolean onlyIfNotBound ) { if (keySeq != null && keySeq.length() > 0) { @@ -125,13 +125,13 @@ map.anotherKey = function; } else { Object op = map.mapping[c]; - if (onlyIfNotBound == false - || op == null - || op == Operation.DO_LOWERCASE_VERSION + if (onlyIfNotBound == false + || op == null + || op == Operation.DO_LOWERCASE_VERSION || op == Operation.VI_MOVEMENT_MODE ) { - + } - + map.mapping[c] = function; } } @@ -148,7 +148,7 @@ } private static void bindArrowKeys(KeyMap map) { - + // MS-DOS bind( map, "\033[0A", Operation.PREVIOUS_HISTORY ); bind( map, "\033[0B", Operation.BACKWARD_CHAR ); @@ -224,27 +224,27 @@ public static char meta( char c ) { return (char) (c | 0x80); } - + public static Map keyMaps() { Map keyMaps = new HashMap(); - + KeyMap emacs = emacs(); bindArrowKeys(emacs); keyMaps.put(EMACS, emacs); keyMaps.put(EMACS_STANDARD, emacs); keyMaps.put(EMACS_CTLX, (KeyMap) emacs.getBound("\u0018")); keyMaps.put(EMACS_META, (KeyMap) emacs.getBound("\u001b")); - + KeyMap viMov = viMovement(); bindArrowKeys(viMov); keyMaps.put(VI_MOVE, viMov); keyMaps.put("vi-command", viMov); - + KeyMap viIns = viInsertion(); bindArrowKeys(viIns); keyMaps.put(VI_INSERT, viIns); keyMaps.put("vi", viIns); - + return keyMaps; } @@ -420,7 +420,7 @@ null, /* Control-A */ null, /* Control-B */ Operation.INTERRUPT, /* Control-C */ - /* + /* * ^D is supposed to move down half a screen. In bash * appears to be ignored. */ @@ -438,13 +438,13 @@ null, /* Control-O */ Operation.VI_PREVIOUS_HISTORY, /* Control-P */ /* - * My testing with readline is the ^Q is ignored. + * My testing with readline is the ^Q is ignored. * Maybe this should be null? */ Operation.QUOTED_INSERT, /* Control-Q */ - + /* - * TODO - Very broken. While in forward/reverse + * TODO - Very broken. While in forward/reverse * history search the VI keyset should go out the * window and we need to enter a very simple keymap. */ --- old/jdk/src/jdk.jline/share/classes/jdk/internal/jline/console/KillRing.java 2015-06-18 03:06:01.383218967 -0700 +++ new/jdk/src/jdk.jline/share/classes/jdk/internal/jline/console/KillRing.java 2015-06-18 03:06:01.213217737 -0700 @@ -6,7 +6,7 @@ * * http://www.opensource.org/licenses/bsd-license.php */ -package jline.console; +package jdk.internal.jline.console; /** * The kill ring class keeps killed text in a fixed size ring. In this --- old/jdk/src/jdk.jline/share/classes/jdk/internal/jline/console/Operation.java 2015-06-18 03:06:02.056223834 -0700 +++ new/jdk/src/jdk.jline/share/classes/jdk/internal/jline/console/Operation.java 2015-06-18 03:06:01.886222605 -0700 @@ -6,7 +6,7 @@ * * http://www.opensource.org/licenses/bsd-license.php */ -package jline.console; +package jdk.internal.jline.console; /** * List of all operations. --- old/jdk/src/jdk.jline/share/classes/jdk/internal/jline/console/UserInterruptException.java 2015-06-18 03:06:02.605227806 -0700 +++ new/jdk/src/jdk.jline/share/classes/jdk/internal/jline/console/UserInterruptException.java 2015-06-18 03:06:02.445226648 -0700 @@ -6,7 +6,7 @@ * * http://www.opensource.org/licenses/bsd-license.php */ -package jline.console; +package jdk.internal.jline.console; /** * This exception is thrown by {@link ConsoleReader#readLine} when @@ -17,6 +17,8 @@ public class UserInterruptException extends RuntimeException { + private static final long serialVersionUID = 6172232572140736750L; + private final String partialLine; public UserInterruptException(String partialLine) --- old/jdk/src/jdk.jline/share/classes/jdk/internal/jline/console/completer/AggregateCompleter.java 2015-06-18 03:06:03.171231900 -0700 +++ new/jdk/src/jdk.jline/share/classes/jdk/internal/jline/console/completer/AggregateCompleter.java 2015-06-18 03:06:02.987230569 -0700 @@ -6,7 +6,7 @@ * * http://www.opensource.org/licenses/bsd-license.php */ -package jline.console.completer; +package jdk.internal.jline.console.completer; import java.util.ArrayList; import java.util.Arrays; @@ -14,7 +14,7 @@ import java.util.LinkedList; import java.util.List; -import static jline.internal.Preconditions.checkNotNull; +import static jdk.internal.jline.internal.Preconditions.checkNotNull; /** * Completer which contains multiple completers and aggregates them together. --- old/jdk/src/jdk.jline/share/classes/jdk/internal/jline/console/completer/ArgumentCompleter.java 2015-06-18 03:06:03.774236261 -0700 +++ new/jdk/src/jdk.jline/share/classes/jdk/internal/jline/console/completer/ArgumentCompleter.java 2015-06-18 03:06:03.582234873 -0700 @@ -6,9 +6,9 @@ * * http://www.opensource.org/licenses/bsd-license.php */ -package jline.console.completer; +package jdk.internal.jline.console.completer; -import jline.internal.Log; +import jdk.internal.jline.internal.Log; import java.util.ArrayList; import java.util.Arrays; @@ -16,7 +16,7 @@ import java.util.LinkedList; import java.util.List; -import static jline.internal.Preconditions.checkNotNull; +import static jdk.internal.jline.internal.Preconditions.checkNotNull; /** * A {@link Completer} implementation that invokes a child completer using the appropriate separator argument. --- old/jdk/src/jdk.jline/share/classes/jdk/internal/jline/console/completer/CandidateListCompletionHandler.java 2015-06-18 03:06:04.344240385 -0700 +++ new/jdk/src/jdk.jline/share/classes/jdk/internal/jline/console/completer/CandidateListCompletionHandler.java 2015-06-18 03:06:04.146238953 -0700 @@ -6,10 +6,10 @@ * * http://www.opensource.org/licenses/bsd-license.php */ -package jline.console.completer; +package jdk.internal.jline.console.completer; -import jline.console.ConsoleReader; -import jline.console.CursorBuffer; +import jdk.internal.jline.console.ConsoleReader; +import jdk.internal.jline.console.CursorBuffer; import java.io.IOException; import java.util.ArrayList; --- old/jdk/src/jdk.jline/share/classes/jdk/internal/jline/console/completer/Completer.java 2015-06-18 03:06:04.890244334 -0700 +++ new/jdk/src/jdk.jline/share/classes/jdk/internal/jline/console/completer/Completer.java 2015-06-18 03:06:04.713243053 -0700 @@ -6,7 +6,7 @@ * * http://www.opensource.org/licenses/bsd-license.php */ -package jline.console.completer; +package jdk.internal.jline.console.completer; import java.util.List; --- old/jdk/src/jdk.jline/share/classes/jdk/internal/jline/console/completer/CompletionHandler.java 2015-06-18 03:06:05.600249469 -0700 +++ new/jdk/src/jdk.jline/share/classes/jdk/internal/jline/console/completer/CompletionHandler.java 2015-06-18 03:06:05.345247625 -0700 @@ -6,9 +6,9 @@ * * http://www.opensource.org/licenses/bsd-license.php */ -package jline.console.completer; +package jdk.internal.jline.console.completer; -import jline.console.ConsoleReader; +import jdk.internal.jline.console.ConsoleReader; import java.io.IOException; import java.util.List; --- old/jdk/src/jdk.jline/share/classes/jdk/internal/jline/console/completer/EnumCompleter.java 2015-06-18 03:06:06.186253708 -0700 +++ new/jdk/src/jdk.jline/share/classes/jdk/internal/jline/console/completer/EnumCompleter.java 2015-06-18 03:06:06.003252384 -0700 @@ -6,9 +6,9 @@ * * http://www.opensource.org/licenses/bsd-license.php */ -package jline.console.completer; +package jdk.internal.jline.console.completer; -import static jline.internal.Preconditions.checkNotNull; +import static jdk.internal.jline.internal.Preconditions.checkNotNull; /** * {@link Completer} for {@link Enum} names. @@ -19,11 +19,11 @@ public class EnumCompleter extends StringsCompleter { - public EnumCompleter(Class source) { + public EnumCompleter(Class> source) { checkNotNull(source); for (Enum n : source.getEnumConstants()) { this.getStrings().add(n.name().toLowerCase()); } } -} \ No newline at end of file +} --- old/jdk/src/jdk.jline/share/classes/jdk/internal/jline/console/completer/FileNameCompleter.java 2015-06-18 03:06:06.777257983 -0700 +++ new/jdk/src/jdk.jline/share/classes/jdk/internal/jline/console/completer/FileNameCompleter.java 2015-06-18 03:06:06.575256522 -0700 @@ -6,14 +6,14 @@ * * http://www.opensource.org/licenses/bsd-license.php */ -package jline.console.completer; +package jdk.internal.jline.console.completer; -import jline.internal.Configuration; +import jdk.internal.jline.internal.Configuration; import java.io.File; import java.util.List; -import static jline.internal.Preconditions.checkNotNull; +import static jdk.internal.jline.internal.Preconditions.checkNotNull; /** * A file name completer takes the buffer and issues a list of --- old/jdk/src/jdk.jline/share/classes/jdk/internal/jline/console/completer/NullCompleter.java 2015-06-18 03:06:07.323261933 -0700 +++ new/jdk/src/jdk.jline/share/classes/jdk/internal/jline/console/completer/NullCompleter.java 2015-06-18 03:06:07.168260812 -0700 @@ -6,7 +6,7 @@ * * http://www.opensource.org/licenses/bsd-license.php */ -package jline.console.completer; +package jdk.internal.jline.console.completer; import java.util.List; @@ -25,4 +25,4 @@ public int complete(final String buffer, final int cursor, final List candidates) { return -1; } -} \ No newline at end of file +} --- old/jdk/src/jdk.jline/share/classes/jdk/internal/jline/console/completer/StringsCompleter.java 2015-06-18 03:06:07.868265875 -0700 +++ new/jdk/src/jdk.jline/share/classes/jdk/internal/jline/console/completer/StringsCompleter.java 2015-06-18 03:06:07.705264696 -0700 @@ -6,7 +6,7 @@ * * http://www.opensource.org/licenses/bsd-license.php */ -package jline.console.completer; +package jdk.internal.jline.console.completer; import java.util.Arrays; import java.util.Collection; @@ -14,7 +14,7 @@ import java.util.SortedSet; import java.util.TreeSet; -import static jline.internal.Preconditions.checkNotNull; +import static jdk.internal.jline.internal.Preconditions.checkNotNull; /** * Completer for a set of strings. @@ -67,4 +67,4 @@ return candidates.isEmpty() ? -1 : 0; } -} \ No newline at end of file +} --- old/jdk/src/jdk.jline/share/classes/jdk/internal/jline/console/completer/package-info.java 2015-06-18 03:06:08.429269933 -0700 +++ new/jdk/src/jdk.jline/share/classes/jdk/internal/jline/console/completer/package-info.java 2015-06-18 03:06:08.262268724 -0700 @@ -11,4 +11,4 @@ * * @since 2.3 */ -package jline.console.completer; \ No newline at end of file +package jdk.internal.jline.console.completer; --- old/jdk/src/jdk.jline/share/classes/jdk/internal/jline/console/history/FileHistory.java 2015-06-18 03:06:09.006274106 -0700 +++ new/jdk/src/jdk.jline/share/classes/jdk/internal/jline/console/history/FileHistory.java 2015-06-18 03:06:08.836272876 -0700 @@ -6,7 +6,7 @@ * * http://www.opensource.org/licenses/bsd-license.php */ -package jline.console.history; +package jdk.internal.jline.console.history; import java.io.BufferedOutputStream; import java.io.BufferedReader; @@ -20,9 +20,8 @@ import java.io.PrintStream; import java.io.Reader; -import jline.internal.Log; - -import static jline.internal.Preconditions.checkNotNull; +import jdk.internal.jline.internal.Log; +import static jdk.internal.jline.internal.Preconditions.checkNotNull; /** * {@link History} using a file for persistent backing. @@ -104,4 +103,4 @@ Log.warn("Failed to delete history file: ", file); } } -} \ No newline at end of file +} --- old/jdk/src/jdk.jline/share/classes/jdk/internal/jline/console/history/History.java 2015-06-18 03:06:09.598278387 -0700 +++ new/jdk/src/jdk.jline/share/classes/jdk/internal/jline/console/history/History.java 2015-06-18 03:06:09.372276753 -0700 @@ -6,7 +6,7 @@ * * http://www.opensource.org/licenses/bsd-license.php */ -package jline.console.history; +package jdk.internal.jline.console.history; import java.util.Iterator; import java.util.ListIterator; @@ -72,7 +72,7 @@ // // Entries // - + interface Entry { int index(); --- old/jdk/src/jdk.jline/share/classes/jdk/internal/jline/console/history/MemoryHistory.java 2015-06-18 03:06:10.324283638 -0700 +++ new/jdk/src/jdk.jline/share/classes/jdk/internal/jline/console/history/MemoryHistory.java 2015-06-18 03:06:10.060281729 -0700 @@ -6,14 +6,14 @@ * * http://www.opensource.org/licenses/bsd-license.php */ -package jline.console.history; +package jdk.internal.jline.console.history; import java.util.Iterator; import java.util.LinkedList; import java.util.ListIterator; import java.util.NoSuchElementException; -import static jline.internal.Preconditions.checkNotNull; +import static jdk.internal.jline.internal.Preconditions.checkNotNull; /** * Non-persistent {@link History}. --- old/jdk/src/jdk.jline/share/classes/jdk/internal/jline/console/history/PersistentHistory.java 2015-06-18 03:06:11.104289282 -0700 +++ new/jdk/src/jdk.jline/share/classes/jdk/internal/jline/console/history/PersistentHistory.java 2015-06-18 03:06:10.909287870 -0700 @@ -6,7 +6,7 @@ * * http://www.opensource.org/licenses/bsd-license.php */ -package jline.console.history; +package jdk.internal.jline.console.history; import java.io.IOException; @@ -32,4 +32,4 @@ * @throws IOException Purge failed */ void purge() throws IOException; -} \ No newline at end of file +} --- old/jdk/src/jdk.jline/share/classes/jdk/internal/jline/console/history/package-info.java 2015-06-18 03:06:11.822294473 -0700 +++ new/jdk/src/jdk.jline/share/classes/jdk/internal/jline/console/history/package-info.java 2015-06-18 03:06:11.651293238 -0700 @@ -11,4 +11,4 @@ * * @since 2.0 */ -package jline.console.history; \ No newline at end of file +package jdk.internal.jline.console.history; --- old/jdk/src/jdk.jline/share/classes/jdk/internal/jline/console/internal/ConsoleReaderInputStream.java 2015-06-18 03:06:12.367298416 -0700 +++ new/jdk/src/jdk.jline/share/classes/jdk/internal/jline/console/internal/ConsoleReaderInputStream.java 2015-06-18 03:06:12.200297209 -0700 @@ -6,10 +6,10 @@ * * http://www.opensource.org/licenses/bsd-license.php */ -package jline.console.internal; - -import jline.console.ConsoleReader; - +package jdk.internal.jline.console.internal; + +import jdk.internal.jline.console.ConsoleReader; + import java.io.IOException; import java.io.InputStream; import java.io.SequenceInputStream; @@ -28,63 +28,63 @@ extends SequenceInputStream { private static InputStream systemIn = System.in; - + public static void setIn() throws IOException { setIn(new ConsoleReader()); } - + public static void setIn(final ConsoleReader reader) { System.setIn(new ConsoleReaderInputStream(reader)); } - + /** * Restore the original {@link System#in} input stream. */ public static void restoreIn() { System.setIn(systemIn); } - + public ConsoleReaderInputStream(final ConsoleReader reader) { super(new ConsoleEnumeration(reader)); } - + private static class ConsoleEnumeration - implements Enumeration + implements Enumeration { private final ConsoleReader reader; private ConsoleLineInputStream next = null; private ConsoleLineInputStream prev = null; - + public ConsoleEnumeration(final ConsoleReader reader) { this.reader = reader; } - - public Object nextElement() { + + public InputStream nextElement() { if (next != null) { InputStream n = next; prev = next; next = null; - + return n; } - + return new ConsoleLineInputStream(reader); } - + public boolean hasMoreElements() { // the last line was null if ((prev != null) && (prev.wasNull == true)) { return false; } - + if (next == null) { next = (ConsoleLineInputStream) nextElement(); } - + return next != null; } } - + private static class ConsoleLineInputStream extends InputStream { @@ -93,31 +93,31 @@ private int index = 0; private boolean eol = false; protected boolean wasNull = false; - + public ConsoleLineInputStream(final ConsoleReader reader) { this.reader = reader; } - + public int read() throws IOException { if (eol) { return -1; } - + if (line == null) { line = reader.readLine(); } - + if (line == null) { wasNull = true; return -1; } - + if (index >= line.length()) { eol = true; return '\n'; // lines are ended with a newline } - + return line.charAt(index++); } } -} \ No newline at end of file +} --- old/jdk/src/jdk.jline/share/classes/jdk/internal/jline/console/internal/ConsoleRunner.java 2015-06-18 03:06:12.937302538 -0700 +++ new/jdk/src/jdk.jline/share/classes/jdk/internal/jline/console/internal/ConsoleRunner.java 2015-06-18 03:06:12.768301317 -0700 @@ -6,13 +6,13 @@ * * http://www.opensource.org/licenses/bsd-license.php */ -package jline.console.internal; - -import jline.console.ConsoleReader; -import jline.console.completer.ArgumentCompleter; -import jline.console.completer.Completer; -import jline.console.history.FileHistory; -import jline.internal.Configuration; +package jdk.internal.jline.console.internal; + +import jdk.internal.jline.console.ConsoleReader; +import jdk.internal.jline.console.completer.ArgumentCompleter; +import jdk.internal.jline.console.completer.Completer; +import jdk.internal.jline.console.history.FileHistory; +import jdk.internal.jline.internal.Configuration; import java.io.File; import java.lang.reflect.Method; @@ -37,17 +37,17 @@ // FIXME: This is really ugly... re-write this public static void main(final String[] args) throws Exception { - List argList = new ArrayList(Arrays.asList(args)); + List argList = new ArrayList(Arrays.asList(args)); if (argList.size() == 0) { usage(); return; } - + String historyFileName = System.getProperty(ConsoleRunner.property, null); - + String mainClass = argList.remove(0); ConsoleReader reader = new ConsoleReader(); - + if (historyFileName != null) { reader.setHistory(new FileHistory(new File(Configuration.getUserHome(), String.format(".jline-%s.%s.history", mainClass, historyFileName)))); @@ -56,24 +56,24 @@ reader.setHistory(new FileHistory(new File(Configuration.getUserHome(), String.format(".jline-%s.history", mainClass)))); } - + String completors = System.getProperty(ConsoleRunner.class.getName() + ".completers", ""); List completorList = new ArrayList(); - + for (StringTokenizer tok = new StringTokenizer(completors, ","); tok.hasMoreTokens();) { Object obj = Class.forName(tok.nextToken()).newInstance(); completorList.add((Completer) obj); } - + if (completorList.size() > 0) { reader.addCompleter(new ArgumentCompleter(completorList)); } - + ConsoleReaderInputStream.setIn(reader); - + try { - Class type = Class.forName(mainClass); - Method method = type.getMethod("main", new Class[]{String[].class}); + Class type = Class.forName(mainClass); + Method method = type.getMethod("main", String[].class); method.invoke(null); } finally { @@ -81,7 +81,7 @@ ConsoleReaderInputStream.restoreIn(); } } - + private static void usage() { System.out.println("Usage: \n java " + "[-Djline.history='name'] " + ConsoleRunner.class.getName() --- old/jdk/src/jdk.jline/share/classes/jdk/internal/jline/console/package-info.java 2015-06-18 03:06:13.642307637 -0700 +++ new/jdk/src/jdk.jline/share/classes/jdk/internal/jline/console/package-info.java 2015-06-18 03:06:13.378305729 -0700 @@ -11,4 +11,4 @@ * * @since 2.0 */ -package jline.console; \ No newline at end of file +package jdk.internal.jline.console; --- old/jdk/src/jdk.jline/share/classes/jdk/internal/jline/internal/Configuration.java 2015-06-18 03:06:14.301312405 -0700 +++ new/jdk/src/jdk.jline/share/classes/jdk/internal/jline/internal/Configuration.java 2015-06-18 03:06:14.132311181 -0700 @@ -6,7 +6,7 @@ * * http://www.opensource.org/licenses/bsd-license.php */ -package jline.internal; +package jdk.internal.jline.internal; import java.io.BufferedInputStream; import java.io.File; @@ -17,7 +17,7 @@ import java.util.Map; import java.util.Properties; -import static jline.internal.Preconditions.checkNotNull; +import static jdk.internal.jline.internal.Preconditions.checkNotNull; /** * Provides access to configuration values. @@ -236,4 +236,4 @@ } return null; } -} \ No newline at end of file +} --- old/jdk/src/jdk.jline/share/classes/jdk/internal/jline/internal/InputStreamReader.java 2015-06-18 03:06:14.936316998 -0700 +++ new/jdk/src/jdk.jline/share/classes/jdk/internal/jline/internal/InputStreamReader.java 2015-06-18 03:06:14.758315709 -0700 @@ -6,7 +6,7 @@ * * http://www.opensource.org/licenses/bsd-license.php */ -package jline.internal; +package jdk.internal.jline.internal; import java.io.IOException; import java.io.InputStream; @@ -39,7 +39,7 @@ * "file.encoding" system property. {@code InputStreamReader} contains a buffer * of bytes read from the source stream and converts these into characters as * needed. The buffer size is 8K. - * + * * @see OutputStreamWriter */ public class InputStreamReader extends Reader { @@ -60,7 +60,7 @@ * {@code in}. This constructor sets the character converter to the encoding * specified in the "file.encoding" property and falls back to ISO 8859_1 * (ISO-Latin-1) if the property doesn't exist. - * + * * @param in * the input stream from which to read characters. */ @@ -80,7 +80,7 @@ * character converter that is used to decode bytes into characters is * identified by name by {@code enc}. If the encoding cannot be found, an * UnsupportedEncodingException error is thrown. - * + * * @param in * the InputStream from which to read characters. * @param enc @@ -111,7 +111,7 @@ /** * Constructs a new InputStreamReader on the InputStream {@code in} and * CharsetDecoder {@code dec}. - * + * * @param in * the source InputStream from which to read characters. * @param dec @@ -128,7 +128,7 @@ /** * Constructs a new InputStreamReader on the InputStream {@code in} and * Charset {@code charset}. - * + * * @param in * the source InputStream from which to read characters. * @param charset @@ -146,7 +146,7 @@ /** * Closes this reader. This implementation closes the source InputStream and * releases all local storage. - * + * * @throws IOException * if an error occurs attempting to close this reader. */ @@ -164,7 +164,7 @@ /** * Returns the name of the encoding used to convert bytes into characters. * The value {@code null} is returned if this reader has been closed. - * + * * @return the name of the character converter or {@code null} if this * reader is closed. */ @@ -181,7 +181,7 @@ * reader has been reached. The byte value is either obtained from * converting bytes in this reader's buffer or by first filling the buffer * from the source InputStream and then reading from the buffer. - * + * * @return the character read or -1 if the end of the reader has been * reached. * @throws IOException @@ -206,7 +206,7 @@ * been reached. The bytes are either obtained from converting bytes in this * reader's buffer or by first filling the buffer from the source * InputStream and then reading from the buffer. - * + * * @param buf * the array to store the characters read. * @param offset @@ -247,7 +247,7 @@ // fill the buffer if needed if (needInput) { try { - if ((in.available() == 0) + if ((in.available() == 0) && (out.position() > offset)) { // we could return the result without blocking read break; @@ -316,7 +316,7 @@ * {@code read()} is called. This implementation returns {@code true} if * there are bytes available in the buffer or the source stream has bytes * available. - * + * * @return {@code true} if the receiver will not block when {@code read()} * is called, {@code false} if unknown or blocking will occur. * @throws IOException @@ -335,4 +335,4 @@ } } } -} \ No newline at end of file +} --- old/jdk/src/jdk.jline/share/classes/jdk/internal/jline/internal/Log.java 2015-06-18 03:06:15.511321156 -0700 +++ new/jdk/src/jdk.jline/share/classes/jdk/internal/jline/internal/Log.java 2015-06-18 03:06:15.344319948 -0700 @@ -6,11 +6,11 @@ * * http://www.opensource.org/licenses/bsd-license.php */ -package jline.internal; +package jdk.internal.jline.internal; import java.io.PrintStream; -import static jline.internal.Preconditions.checkNotNull; +import static jdk.internal.jline.internal.Preconditions.checkNotNull; /** * Internal logger. @@ -117,4 +117,4 @@ public static void error(final Object... messages) { log(Level.ERROR, messages); } -} \ No newline at end of file +} --- old/jdk/src/jdk.jline/share/classes/jdk/internal/jline/internal/NonBlockingInputStream.java 2015-06-18 03:06:16.078325257 -0700 +++ new/jdk/src/jdk.jline/share/classes/jdk/internal/jline/internal/NonBlockingInputStream.java 2015-06-18 03:06:15.911324050 -0700 @@ -6,7 +6,7 @@ * * http://www.opensource.org/licenses/bsd-license.php */ -package jline.internal; +package jdk.internal.jline.internal; import java.io.IOException; import java.io.InputStream; @@ -16,8 +16,8 @@ * is non-blocking; that is, reads can be performed against it that timeout * if no data is seen for a period of time. This effect is achieved by having * a separate thread perform all non-blocking read requests and then - * waiting on the thread to complete. - * + * waiting on the thread to complete. + * *

VERY IMPORTANT NOTES *

    *
  • This class is not thread safe. It expects at most one reader. @@ -33,19 +33,19 @@ { private InputStream in; // The actual input stream private int ch = -2; // Recently read character - + private boolean threadIsReading = false; private boolean isShutdown = false; private IOException exception = null; private boolean nonBlockingEnabled; - + /** * Creates a NonBlockingInputStream out of a normal blocking * stream. Note that this call also spawn a separate thread to perform the * blocking I/O on behalf of the thread that is using this class. The * {@link #shutdown()} method must be called in order to shut this thread down. * @param in The input stream to wrap - * @param isNonBlockingEnabled If true, then the non-blocking methods + * @param isNonBlockingEnabled If true, then the non-blocking methods * {@link #read(long)} and {@link #peek(long)} will be available and, * more importantly, the thread will be started to provide support for the * feature. If false, then this class acts as a clean-passthru for the @@ -54,7 +54,7 @@ public NonBlockingInputStream (InputStream in, boolean isNonBlockingEnabled) { this.in = in; this.nonBlockingEnabled = isNonBlockingEnabled; - + if (isNonBlockingEnabled) { Thread t = new Thread(this); t.setName("NonBlockingInputStreamThread"); @@ -62,12 +62,12 @@ t.start(); } } - + /** * Shuts down the thread that is handling blocking I/O. Note that if the * thread is currently blocked waiting for I/O it will not actually * shut down until the I/O is received. Shutting down the I/O thread - * does not prevent this class from being used, but causes the + * does not prevent this class from being used, but causes the * non-blocking methods to fail if called and causes {@link #isNonBlockingEnabled()} * to return false. */ @@ -77,16 +77,16 @@ notify(); } } - + /** * Non-blocking is considered enabled if the feature is enabled and the - * I/O thread has not been shut down. + * I/O thread has not been shut down. * @return true if non-blocking mode is enabled. */ public boolean isNonBlockingEnabled() { return nonBlockingEnabled && !isShutdown; } - + @Override public void close() throws IOException { /* @@ -103,11 +103,11 @@ return read(0L, false); return in.read (); } - + /** * Peeks to see if there is a byte waiting in the input stream without * actually consuming the byte. - * + * * @param timeout The amount of time to wait, 0 == forever * @return -1 on eof, -2 if the timeout expired with no available input * or the character that was read (without consuming it). @@ -120,7 +120,7 @@ } return read(timeout, true); } - + /** * Attempts to read a character from the input stream for a specific * period of time. @@ -136,7 +136,7 @@ } return read(timeout, false); } - + /** * Attempts to read a character from the input stream for a specific * period of time. @@ -156,7 +156,7 @@ exception = null; throw toBeThrown; } - + /* * If there was a pending character from the thread, then * we send it. If the timeout is 0L or the thread was shut down @@ -176,43 +176,43 @@ threadIsReading = true; notify(); } - + boolean isInfinite = (timeout <= 0L); - + /* * So the thread is currently doing the reading for us. So * now we play the waiting game. */ while (isInfinite || timeout > 0L) { long start = System.currentTimeMillis (); - + try { wait(timeout); } catch (InterruptedException e) { /* IGNORED */ } - + if (exception != null) { assert ch == -2; - + IOException toBeThrown = exception; if (!isPeek) exception = null; throw toBeThrown; } - + if (ch >= -1) { assert exception == null; break; } - + if (!isInfinite) { timeout -= System.currentTimeMillis() - start; } } } - + /* * ch is the character that was just read. Either we set it because * a local read was performed or the read thread set it (or failed to @@ -225,11 +225,11 @@ } return ret; } - + /** - * This version of read() is very specific to jline's purposes, it + * This version of read() is very specific to jline's purposes, it * will always always return a single byte at a time, rather than filling - * the entire buffer. + * the entire buffer. */ @Override public int read (byte[] b, int off, int len) throws IOException { @@ -246,7 +246,7 @@ c = this.read(0L); else c = in.read(); - + if (c == -1) { return -1; } @@ -259,9 +259,9 @@ Log.debug("NonBlockingInputStream start"); boolean needToShutdown = false; boolean needToRead = false; - + while (!needToShutdown) { - + /* * Synchronize to grab variables accessed by both this thread * and the accessing thread. @@ -269,7 +269,7 @@ synchronized (this) { needToShutdown = this.isShutdown; needToRead = this.threadIsReading; - + try { /* * Nothing to do? Then wait. @@ -282,7 +282,7 @@ /* IGNORED */ } } - + /* * We're not shutting down, but we need to read. This cannot * happen while we are holding the lock (which we aren't now). @@ -296,7 +296,7 @@ catch (IOException e) { failure = e; } - + /* * Re-grab the lock to update the state. */ @@ -308,7 +308,7 @@ } } } - + Log.debug("NonBlockingInputStream shutdown"); } } --- old/jdk/src/jdk.jline/share/classes/jdk/internal/jline/internal/Nullable.java 2015-06-18 03:06:16.699329750 -0700 +++ new/jdk/src/jdk.jline/share/classes/jdk/internal/jline/internal/Nullable.java 2015-06-18 03:06:16.530328526 -0700 @@ -6,7 +6,7 @@ * * http://www.opensource.org/licenses/bsd-license.php */ -package jline.internal; +package jdk.internal.jline.internal; import java.lang.annotation.*; --- old/jdk/src/jdk.jline/share/classes/jdk/internal/jline/internal/Preconditions.java 2015-06-18 03:06:17.280333951 -0700 +++ new/jdk/src/jdk.jline/share/classes/jdk/internal/jline/internal/Preconditions.java 2015-06-18 03:06:17.120332794 -0700 @@ -6,7 +6,7 @@ * * http://www.opensource.org/licenses/bsd-license.php */ -package jline.internal; +package jdk.internal.jline.internal; // Some bits lifted from Guava's ( http://code.google.com/p/guava-libraries/ ) Preconditions. @@ -24,4 +24,4 @@ } return reference; } -} \ No newline at end of file +} --- old/jdk/src/jdk.jline/share/classes/jdk/internal/jline/internal/ShutdownHooks.java 2015-06-18 03:06:17.827337907 -0700 +++ new/jdk/src/jdk.jline/share/classes/jdk/internal/jline/internal/ShutdownHooks.java 2015-06-18 03:06:17.664336728 -0700 @@ -6,12 +6,12 @@ * * http://www.opensource.org/licenses/bsd-license.php */ -package jline.internal; +package jdk.internal.jline.internal; import java.util.ArrayList; import java.util.List; -import static jline.internal.Preconditions.checkNotNull; +import static jdk.internal.jline.internal.Preconditions.checkNotNull; /** * Manages the JLine shutdown-hook thread and tasks to execute on shutdown. @@ -125,4 +125,4 @@ { void run() throws Exception; } -} \ No newline at end of file +} --- old/jdk/src/jdk.jline/share/classes/jdk/internal/jline/internal/TerminalLineSettings.java 2015-06-18 03:06:18.486342674 -0700 +++ new/jdk/src/jdk.jline/share/classes/jdk/internal/jline/internal/TerminalLineSettings.java 2015-06-18 03:06:18.326341515 -0700 @@ -6,7 +6,7 @@ * * http://www.opensource.org/licenses/bsd-license.php */ -package jline.internal; +package jdk.internal.jline.internal; import java.io.ByteArrayOutputStream; import java.io.Closeable; @@ -17,7 +17,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import static jline.internal.Preconditions.checkNotNull; +import static jdk.internal.jline.internal.Preconditions.checkNotNull; /** * Provides access to terminal line settings via stty. @@ -25,7 +25,7 @@ * @author Marc Prud'hommeaux * @author Dale Kemp * @author Jason Dillon - * @author Jean-Baptiste Onofré + * @author Jean-Baptiste Onofr\u00E9 * @since 2.0 */ public final class TerminalLineSettings @@ -109,7 +109,7 @@ configLastFetched = currentTime; } - return this.getProperty(name, config); + return getProperty(name, config); } /** --- old/jdk/src/jdk.jline/share/classes/jdk/internal/jline/internal/TestAccessible.java 2015-06-18 03:06:19.065346860 -0700 +++ new/jdk/src/jdk.jline/share/classes/jdk/internal/jline/internal/TestAccessible.java 2015-06-18 03:06:18.892345609 -0700 @@ -6,7 +6,7 @@ * * http://www.opensource.org/licenses/bsd-license.php */ -package jline.internal; +package jdk.internal.jline.internal; import java.lang.annotation.Documented; import java.lang.annotation.Retention; @@ -30,4 +30,4 @@ public @interface TestAccessible { // empty -} \ No newline at end of file +} --- old/jdk/src/jdk.jline/share/classes/jdk/internal/jline/internal/Urls.java 2015-06-18 03:06:19.636350990 -0700 +++ new/jdk/src/jdk.jline/share/classes/jdk/internal/jline/internal/Urls.java 2015-06-18 03:06:19.468349774 -0700 @@ -6,7 +6,7 @@ * * http://www.opensource.org/licenses/bsd-license.php */ -package jline.internal; +package jdk.internal.jline.internal; import java.io.File; import java.net.MalformedURLException; @@ -41,4 +41,4 @@ throw new IllegalStateException(e); } } -} \ No newline at end of file +} --- old/jdk/src/jdk.jline/share/classes/jdk/internal/jline/internal/package-info.java 2015-06-18 03:06:20.186354968 -0700 +++ new/jdk/src/jdk.jline/share/classes/jdk/internal/jline/internal/package-info.java 2015-06-18 03:06:20.031353849 -0700 @@ -11,4 +11,4 @@ * * @since 2.0 */ -package jline.internal; \ No newline at end of file +package jdk.internal.jline.internal; --- old/jdk/src/jdk.jline/share/classes/jdk/internal/jline/package-info.java 2015-06-18 03:06:20.912360218 -0700 +++ new/jdk/src/jdk.jline/share/classes/jdk/internal/jline/package-info.java 2015-06-18 03:06:20.579357810 -0700 @@ -11,4 +11,4 @@ * * @since 2.0 */ -package jline; \ No newline at end of file +package jdk.internal.jline; --- old/jdk/test/TEST.groups 2015-06-18 03:06:21.697365896 -0700 +++ new/jdk/test/TEST.groups 2015-06-18 03:06:21.522364630 -0700 @@ -194,6 +194,9 @@ jdk_jdi = \ com/sun/jdi +jdk_jline = \ + jdk/internal/jline + jdk_native_sanity = \ native_sanity @@ -261,6 +264,7 @@ :jdk_util \ :jdk_math \ :jdk_io \ + :jdk_jline \ :jdk_nio \ :jdk_net \ :jdk_rmi \ --- /dev/null 2015-04-26 06:51:08.003313989 -0700 +++ new/jdk/make/lib/Lib-jdk.jline.gmk 2015-06-18 03:06:22.089368731 -0700 @@ -0,0 +1,60 @@ +# +# Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved. +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# This code is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License version 2 only, as +# published by the Free Software Foundation. Oracle designates this +# particular file as subject to the "Classpath" exception as provided +# by Oracle in the LICENSE file that accompanied this code. +# +# This code is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# version 2 for more details (a copy is included in the LICENSE file that +# accompanied this code). +# +# You should have received a copy of the GNU General Public License version +# 2 along with this work; if not, write to the Free Software Foundation, +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. +# +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA +# or visit www.oracle.com if you need additional information or have any +# questions. +# + +include LibCommon.gmk + +################################################################################ + +ifeq ($(OPENJDK_TARGET_OS), windows) + + LIBJLINE_SRC := $(JDK_TOPDIR)/src/jdk.jline/$(OPENJDK_TARGET_OS_TYPE)/native/libjline \ + # + LIBJLINE_CPPFLAGS := -I$(INCLUDEDIR) -I$(JDK_OUTPUTDIR)/include/$(OPENJDK_TARGET_OS) \ + $(addprefix -I, $(LIBJLINE_SRC)) \ + -I$(SUPPORT_OUTPUTDIR)/headers/jdk.jline \ + # + + $(eval $(call SetupNativeCompilation,BUILD_LIBJLINE, \ + LIBRARY := jline, \ + OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \ + SRC := $(LIBJLINE_SRC), \ + OPTIMIZATION := LOW, \ + CFLAGS := $(CFLAGS_JDKLIB) $(CFLAGS_WARNINGS_ARE_ERRORS) -DUSE_MMAP \ + $(LIBJLINE_CPPFLAGS), \ + LDFLAGS := $(LDFLAGS_JDKLIB), \ + LDFLAGS_SUFFIX := $(LDFLAGS_JDKLIB_SUFFIX) user32.lib, \ + VERSIONINFO_RESOURCE := $(GLOBAL_VERSION_INFO_RESOURCE), \ + RC_FLAGS := $(RC_FLAGS) \ + -D "JDK_FNAME=jline.dll" \ + -D "JDK_INTERNAL_NAME=jline" \ + -D "JDK_FTYPE=0x2L", \ + OBJECT_DIR := $(SUPPORT_OUTPUTDIR)/native/$(MODULE)/libjline, \ + DEBUG_SYMBOLS := $(DEBUG_ALL_BINARIES))) + + TARGETS += $(BUILD_LIBJLINE) + +endif # OPENJDK_TARGET_OS + +################################################################################ --- /dev/null 2015-04-26 06:51:08.003313989 -0700 +++ new/jdk/src/jdk.jline/windows/native/libjline/WindowsTerminal.cpp 2015-06-18 03:06:22.613372522 -0700 @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "jni.h" +#include "jvm.h" +#include "jdk_internal_jline_WindowsTerminal.h" + +#include +#include +#include + +JNIEXPORT jint JNICALL Java_jdk_internal_jline_WindowsTerminal_getConsoleMode + (JNIEnv *, jobject) { + HANDLE hStdIn; + if ((hStdIn = GetStdHandle(STD_INPUT_HANDLE)) == INVALID_HANDLE_VALUE) { + return -1; + } + DWORD fdwMode; + if (! GetConsoleMode(hStdIn, &fdwMode)) { + return -1; + } + return fdwMode; +} + +JNIEXPORT void JNICALL Java_jdk_internal_jline_WindowsTerminal_setConsoleMode + (JNIEnv *, jobject, jint mode) { + HANDLE hStdIn; + if ((hStdIn = GetStdHandle(STD_INPUT_HANDLE)) == INVALID_HANDLE_VALUE) { + return ; + } + DWORD fdwMode = mode; + SetConsoleMode(hStdIn, fdwMode); +} + +JNIEXPORT jobject JNICALL Java_jdk_internal_jline_WindowsTerminal_readKeyEvent + (JNIEnv *env, jobject) { + HANDLE hStdIn; + if ((hStdIn = GetStdHandle(STD_INPUT_HANDLE)) == INVALID_HANDLE_VALUE) { + return NULL; + } + INPUT_RECORD record; + DWORD n; + while (TRUE) { + if (ReadConsoleInputA(hStdIn, &record, 1, &n) == 0) { + return NULL; + } + if (record.EventType == KEY_EVENT) { + jclass clazz = env->FindClass("jdk/internal/jline/WindowsTerminal$KEY_EVENT_RECORD"); + jmethodID constr = env->GetMethodID(clazz, "", "(ZCIII)V"); + return env->NewObject(clazz, + constr, + record.Event.KeyEvent.bKeyDown, + record.Event.KeyEvent.uChar.UnicodeChar, + record.Event.KeyEvent.dwControlKeyState, + record.Event.KeyEvent.wVirtualKeyCode, + record.Event.KeyEvent.wRepeatCount); + } + continue; + } +} + +JNIEXPORT jint JNICALL Java_jdk_internal_jline_WindowsTerminal_getConsoleOutputCodepage + (JNIEnv *, jobject) { + return GetConsoleCP(); +} + +JNIEXPORT jint JNICALL Java_jdk_internal_jline_WindowsTerminal_getWindowsTerminalWidth + (JNIEnv *, jobject) { + HANDLE hStdIn; + if ((hStdIn = GetStdHandle(STD_INPUT_HANDLE)) == INVALID_HANDLE_VALUE) { + return -1; + } + CONSOLE_SCREEN_BUFFER_INFO info; + if (! GetConsoleScreenBufferInfo(hStdIn, &info)) { + return -1; + } + return info.dwSize.X; +} + +JNIEXPORT jint JNICALL Java_jdk_internal_jline_WindowsTerminal_getWindowsTerminalHeight + (JNIEnv *, jobject) { + HANDLE hStdIn; + if ((hStdIn = GetStdHandle(STD_INPUT_HANDLE)) == INVALID_HANDLE_VALUE) { + return -1; + } + CONSOLE_SCREEN_BUFFER_INFO info; + if (! GetConsoleScreenBufferInfo(hStdIn, &info)) { + return -1; + } + return info.dwSize.Y; +} --- /dev/null 2015-04-26 06:51:08.003313989 -0700 +++ new/jdk/test/jdk/internal/jline/KeyConversionTest.java 2015-06-18 03:06:23.313377584 -0700 @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * @test + * @bug 8080679 + * @summary Verify the conversion from key events to escape sequences works properly. + */ + +import jdk.internal.jline.WindowsTerminal; +import jdk.internal.jline.WindowsTerminal.KEY_EVENT_RECORD; + +public class KeyConversionTest { + public static void main(String... args) throws Exception { + new KeyConversionTest().run(); + } + + void run() throws Exception { + checkKeyConversion(new KEY_EVENT_RECORD(true, '\0', 256, 37, 1), "\033[D"); //LEFT + checkKeyConversion(new KEY_EVENT_RECORD(true, '\0', 264, 37, 1), "\033[1;5D"); //Ctrl-LEFT + checkKeyConversion(new KEY_EVENT_RECORD(true, '\0', 258, 37, 1), "\033[1;3D"); //Alt-LEFT + checkKeyConversion(new KEY_EVENT_RECORD(true, '\0', 256, 46, 1), "\033[3~"); //delete + checkKeyConversion(new KEY_EVENT_RECORD(true, '\0', 264, 46, 1), "\033[3;5~"); //Ctrl-delete + checkKeyConversion(new KEY_EVENT_RECORD(true, '\0', 258, 46, 1), "\033[3;3~"); //Alt-delete + checkKeyConversion(new KEY_EVENT_RECORD(true, '\0', 272, 46, 1), "\033[3;2~"); //Shift-delete + checkKeyConversion(new KEY_EVENT_RECORD(true, '\0', 280, 46, 1), "\033[3;6~"); //Ctrl-Shift-delete + checkKeyConversion(new KEY_EVENT_RECORD(true, '\0', 274, 46, 1), "\033[3;4~"); //Alt-Shift-delete + checkKeyConversion(new KEY_EVENT_RECORD(true, '\0', 282, 46, 1), "\033[3;8~"); //Ctrl-Alt-Shift-delete + } + + void checkKeyConversion(KEY_EVENT_RECORD event, String expected) { + String actual = WindowsTerminal.convertKeys(event); + + if (!expected.equals(actual)) { + throw new AssertionError("Expected: " + expected + "; actual: " + actual); + } + } +} --- /dev/null 2015-04-26 06:51:08.003313989 -0700 +++ new/jdk/test/jdk/internal/jline/console/StripAnsiTest.java 2015-06-18 03:06:23.839381387 -0700 @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * @test + * @bug 8080679 + * @summary Verify ConsoleReader.stripAnsi strips escape sequences from its input correctly. + */ + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.lang.reflect.Method; +import jdk.internal.jline.console.ConsoleReader; + +public class StripAnsiTest { + public static void main(String... args) throws Exception { + new StripAnsiTest().run(); + } + + void run() throws Exception { + ByteArrayInputStream in = new ByteArrayInputStream(new byte[0]); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + ConsoleReader reader = new ConsoleReader(in, out); + + String withAnsi = "0\033[s1\033[2J2\033[37;4m3"; + String expected = "0123"; + + Method stripAnsi = ConsoleReader.class.getDeclaredMethod("stripAnsi", String.class); + stripAnsi.setAccessible(true); + String actual = (String) stripAnsi.invoke(reader, withAnsi); + + if (!expected.equals(actual)) { + throw new IllegalStateException("Did not correctly strip escape sequences: " + actual); + } + } +} --- old/jdk/src/jdk.jline/share/classes/jdk/internal/jline/AnsiWindowsTerminal.java 2015-06-18 03:06:24.535386423 -0700 +++ /dev/null 2015-04-26 06:51:08.003313989 -0700 @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2002-2012, the original author or authors. - * - * This software is distributable under the BSD license. See the terms of the - * BSD license in the documentation provided with this software. - * - * http://www.opensource.org/licenses/bsd-license.php - */ -package jline; - -import jline.internal.Configuration; -import org.fusesource.jansi.AnsiConsole; -import org.fusesource.jansi.AnsiOutputStream; -import org.fusesource.jansi.WindowsAnsiOutputStream; - -import java.io.ByteArrayOutputStream; -import java.io.OutputStream; - -/** - * ANSI-supported {@link WindowsTerminal}. - * - * @since 2.0 - */ -public class AnsiWindowsTerminal - extends WindowsTerminal -{ - private final boolean ansiSupported = detectAnsiSupport(); - - @Override - public OutputStream wrapOutIfNeeded(OutputStream out) { - return wrapOutputStream(out); - } - - /** - * Returns an ansi output stream handler. We return whatever was - * passed if we determine we cannot handle ansi based on Kernel32 calls. - * - * @return an @{link AltWindowAnsiOutputStream} instance or the passed - * stream. - */ - private static OutputStream wrapOutputStream(final OutputStream stream) { - if (Configuration.isWindows()) { - // On windows we know the console does not interpret ANSI codes.. - try { - return new WindowsAnsiOutputStream(stream); - } catch (Throwable ignore) { - // this happens when JNA is not in the path.. or - // this happens when the stdout is being redirected to a file. - } - // Use the ANSIOutputStream to strip out the ANSI escape sequences. - return new AnsiOutputStream(stream); - } - return stream; - } - - private static boolean detectAnsiSupport() { - OutputStream out = AnsiConsole.wrapOutputStream(new ByteArrayOutputStream()); - try { - out.close(); - } - catch (Exception e) { - // ignore; - } - return out instanceof WindowsAnsiOutputStream; - } - - public AnsiWindowsTerminal() throws Exception { - super(); - } - - @Override - public boolean isAnsiSupported() { - return ansiSupported; - } - - @Override - public boolean hasWeirdWrap() { - return false; - } -}