< prev index next >

jdk/src/jdk.jline/share/classes/jdk/internal/jline/console/ConsoleReader.java

Print this page

        

*** 4,14 **** * 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.console; import java.awt.*; import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.Transferable; --- 4,14 ---- * 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 jdk.internal.jline.console; import java.awt.*; import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.Transferable;
*** 35,62 **** import java.util.List; import java.util.ListIterator; import java.util.Map; import java.util.ResourceBundle; import java.util.Stack; ! 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 static jline.internal.Preconditions.checkNotNull; /** * A reader for console applications. It supports custom tab-completion, * saveable command history, and command line editing. On some platforms, * platform-specific commands will need to be issued before the reader will --- 35,63 ---- import java.util.List; import java.util.ListIterator; import java.util.Map; import java.util.ResourceBundle; import java.util.Stack; + import java.util.regex.Pattern; ! 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 jdk.internal.jline.internal.Preconditions.checkNotNull; /** * A reader for console applications. It supports custom tab-completion, * saveable command history, and command line editing. On some platforms, * platform-specific commands will need to be issued before the reader will
*** 513,534 **** } return str; } ! private 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; ! } } /** * Move the cursor position to the specified absolute index. */ public final boolean setCursorPosition(final int position) throws IOException { --- 514,538 ---- } return str; } ! String stripAnsi(String str) { if (str == null) return ""; ! 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. */ public final boolean setCursorPosition(final int position) throws IOException {
*** 663,672 **** --- 667,677 ---- /** * 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++) { char c = str.charAt(i); switch (c) {
*** 1365,1375 **** if (isForward) { while (count-- > 0) { int pos = buf.cursor + 1; while (pos < buf.buffer.length()) { ! if (buf.buffer.charAt(pos) == (char) searchChar) { setCursorPosition(pos); ok = true; break; } ++pos; --- 1370,1380 ---- if (isForward) { while (count-- > 0) { int pos = buf.cursor + 1; while (pos < buf.buffer.length()) { ! if (buf.buffer.charAt(pos) == searchChar) { setCursorPosition(pos); ok = true; break; } ++pos;
*** 1393,1403 **** } else { while (count-- > 0) { int pos = buf.cursor - 1; while (pos >= 0) { ! if (buf.buffer.charAt(pos) == (char) searchChar) { setCursorPosition(pos); ok = true; break; } --pos; --- 1398,1408 ---- } else { while (count-- > 0) { int pos = buf.cursor - 1; while (pos >= 0) { ! if (buf.buffer.charAt(pos) == searchChar) { setCursorPosition(pos); ok = true; break; } --pos;
*** 1608,1617 **** --- 1613,1623 ---- /** * Implements vi search ("/" or "?"). * @throws IOException */ + @SuppressWarnings("fallthrough") private int viSearch(char searchChar) throws IOException { boolean isForward = (searchChar == '/'); /* * This is a little gross, I'm sure there is a more appropriate way
*** 2907,2917 **** * aborted yank-to, delete-to, change-to then * don't move the cursor back. The cursor is * only move on an expclit entry to movement * mode. */ ! if (state == state.NORMAL) { moveCursor(-1); } consoleKeys.setKeyMap(KeyMap.VI_MOVE); break; --- 2913,2923 ---- * aborted yank-to, delete-to, change-to then * don't move the cursor back. The cursor is * only move on an expclit entry to movement * mode. */ ! if (state == State.NORMAL) { moveCursor(-1); } consoleKeys.setKeyMap(KeyMap.VI_MOVE); break;
*** 3598,3607 **** --- 3604,3614 ---- if (transferable == null) { return false; } try { + @SuppressWarnings("deprecation") Object content = transferable.getTransferData(DataFlavor.plainTextFlavor); // This fix was suggested in bug #1060649 at // http://sourceforge.net/tracker/index.php?func=detail&aid=1060649&group_id=64033&atid=506056 // to get around the deprecated DataFlavor.plainTextFlavor, but it
< prev index next >