--- 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