You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by gn...@apache.org on 2017/09/20 13:51:01 UTC
karaf git commit: [KARAF-5382] Karaf shell session.readLine consumes
backslashes
Repository: karaf
Updated Branches:
refs/heads/master 2e99ce8f6 -> 56718ec70
[KARAF-5382] Karaf shell session.readLine consumes backslashes
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/56718ec7
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/56718ec7
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/56718ec7
Branch: refs/heads/master
Commit: 56718ec700554af247f90e54ff20a12d68206ac4
Parents: 2e99ce8
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Wed Sep 20 15:50:49 2017 +0200
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Wed Sep 20 15:50:58 2017 +0200
----------------------------------------------------------------------
.../shell/impl/console/ConsoleSessionImpl.java | 57 +++++++++++++++++---
1 file changed, 51 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/56718ec7/shell/core/src/main/java/org/apache/karaf/shell/impl/console/ConsoleSessionImpl.java
----------------------------------------------------------------------
diff --git a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/ConsoleSessionImpl.java b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/ConsoleSessionImpl.java
index 2151e11..f1a0772 100644
--- a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/ConsoleSessionImpl.java
+++ b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/ConsoleSessionImpl.java
@@ -29,6 +29,7 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -513,12 +514,15 @@ public class ConsoleSessionImpl implements Session {
@Override
public String readLine(String prompt, Character mask) throws IOException {
- try {
- reader.getVariables().put(LineReader.DISABLE_HISTORY, Boolean.TRUE);
- return reader.readLine(prompt, mask);
- } finally {
- reader.getVariables().remove(LineReader.DISABLE_HISTORY);
- }
+ LineReader reader = LineReaderBuilder.builder()
+ .terminal(jlineTerminal)
+ .appName("karaf")
+ .parser((line, cursor, context) -> new SimpleParsedLine(line, cursor))
+ .build();
+ reader.setOpt(LineReader.Option.DISABLE_EVENT_EXPANSION);
+ reader.setVariable(LineReader.DISABLE_HISTORY, Boolean.TRUE);
+ reader.setVariable(LineReader.DISABLE_COMPLETION, Boolean.TRUE);
+ return reader.readLine(prompt, mask);
}
private String loadCompletionMode() {
@@ -626,6 +630,47 @@ public class ConsoleSessionImpl implements Session {
return parts[0];
}
+ private static class SimpleParsedLine implements ParsedLine {
+
+ private final String line;
+ private final int cursor;
+
+ public SimpleParsedLine(String line, int cursor) {
+ this.line = line;
+ this.cursor = cursor;
+ }
+
+ @Override
+ public String word() {
+ return line;
+ }
+
+ @Override
+ public int wordCursor() {
+ return cursor;
+ }
+
+ @Override
+ public int wordIndex() {
+ return 0;
+ }
+
+ @Override
+ public List<String> words() {
+ return Collections.singletonList(line);
+ }
+
+ @Override
+ public String line() {
+ return line;
+ }
+
+ @Override
+ public int cursor() {
+ return cursor;
+ }
+ }
+
private class AggregateMaskingCallback implements MaskingCallback {
private final List<Command> commands = new ArrayList<>();