You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by md...@apache.org on 2013/10/28 16:01:34 UTC
git commit: ACCUMULO-1042 use jline 2.11 for ctrl-c
Updated Branches:
refs/heads/master 32f423e63 -> 8fb6c8607
ACCUMULO-1042 use jline 2.11 for ctrl-c
Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/8fb6c860
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/8fb6c860
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/8fb6c860
Branch: refs/heads/master
Commit: 8fb6c860709419e95b16d18af3d4101ae035abd2
Parents: 32f423e
Author: Mike Drob <md...@mdrob.com>
Authored: Mon Oct 28 10:56:08 2013 -0400
Committer: Mike Drob <md...@mdrob.com>
Committed: Mon Oct 28 10:56:08 2013 -0400
----------------------------------------------------------------------
.../apache/accumulo/core/util/shell/Shell.java | 51 +++++++++++++-------
1 file changed, 34 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/accumulo/blob/8fb6c860/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java b/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java
index 4140c8c..52e1d04 100644
--- a/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java
+++ b/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java
@@ -35,6 +35,7 @@ import java.util.TreeMap;
import java.util.UUID;
import jline.console.ConsoleReader;
+import jline.console.UserInterruptException;
import jline.console.history.FileHistory;
import org.apache.accumulo.core.Constants;
@@ -473,6 +474,9 @@ public class Shell extends ShellOptions {
// This would be a nice feature but !METADATA screws it up
reader.setExpandEvents(false);
+ // Turn Ctrl+C into Exception instead of JVM exit
+ reader.setHandleUserInterrupt(true);
+
ShellCompletor userCompletor = null;
if (execFile != null) {
@@ -492,26 +496,39 @@ public class Shell extends ShellOptions {
}
while (true) {
- if (hasExited())
- return exitCode;
+ try {
+ if (hasExited())
+ return exitCode;
- // If tab completion is true we need to reset
- if (tabCompletion) {
- if (userCompletor != null)
- reader.removeCompleter(userCompletor);
-
- userCompletor = setupCompletion();
- reader.addCompleter(userCompletor);
- }
+ // If tab completion is true we need to reset
+ if (tabCompletion) {
+ if (userCompletor != null)
+ reader.removeCompleter(userCompletor);
+
+ userCompletor = setupCompletion();
+ reader.addCompleter(userCompletor);
+ }
- reader.setPrompt(getDefaultPrompt());
- input = reader.readLine();
- if (input == null) {
- reader.println();
- return exitCode;
- } // user canceled
+ reader.setPrompt(getDefaultPrompt());
+ input = reader.readLine();
+ if (input == null) {
+ reader.println();
+ return exitCode;
+ } // User Canceled (Ctrl+D)
- execCommand(input, disableAuthTimeout, false);
+ execCommand(input, disableAuthTimeout, false);
+ } catch (UserInterruptException uie) {
+ // User Cancelled (Ctrl+C)
+ reader.println();
+
+ String partialLine = uie.getPartialLine();
+ if (partialLine == null || "".equals(uie.getPartialLine().trim())) {
+ // No content, actually exit
+ return exitCode;
+ }
+ } finally {
+ reader.flush();
+ }
}
}