< prev index next >
jdk/src/jdk.jline/share/classes/jdk/internal/jline/console/ConsoleReader.java
Print this page
@@ -4,11 +4,11 @@
* 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;
+package jdk.internal.jline.console;
import java.awt.*;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
@@ -35,28 +35,29 @@
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 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,
* saveable command history, and command line editing. On some platforms,
* platform-specific commands will need to be issued before the reader will
@@ -513,22 +514,25 @@
}
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.
*/
public final boolean setCursorPosition(final int position) throws IOException {
@@ -663,10 +667,11 @@
/**
* 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,11 +1370,11 @@
if (isForward) {
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;
}
++pos;
@@ -1393,11 +1398,11 @@
}
else {
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;
}
--pos;
@@ -1608,10 +1613,11 @@
/**
* 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,11 +2913,11 @@
* 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) {
+ if (state == State.NORMAL) {
moveCursor(-1);
}
consoleKeys.setKeyMap(KeyMap.VI_MOVE);
break;
@@ -3598,10 +3604,11 @@
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 >