karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject karaf git commit: Refactor completer creation
Date Tue, 01 Aug 2017 12:16:23 GMT
Repository: karaf
Updated Branches:
  refs/heads/master ff6d8a08d -> a4d996815


Refactor completer creation


Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/a4d99681
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/a4d99681
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/a4d99681

Branch: refs/heads/master
Commit: a4d9968156355d07ec55a21476aa5c95c7dbd839
Parents: ff6d8a0
Author: Christian Schneider <chris@die-schneider.net>
Authored: Tue Aug 1 13:48:27 2017 +0200
Committer: Christian Schneider <chris@die-schneider.net>
Committed: Tue Aug 1 13:48:27 2017 +0200

----------------------------------------------------------------------
 .../shell/impl/console/ConsoleSessionImpl.java  | 63 +++++++++++---------
 1 file changed, 34 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/a4d99681/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 3efac34..f787f31 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
@@ -144,32 +144,12 @@ public class ConsoleSessionImpl implements Session {
                 jlineTerminal.output());
 
         // Completers
-        Completers.CompletionEnvironment env = new Completers.CompletionEnvironment() {
-            @Override
-            public Map<String, List<Completers.CompletionData>> getCompletions()
{
-                return Shell.getCompletions(session);
-            }
-            @Override
-            public Set<String> getCommands() {
-                return Shell.getCommands(session);
-            }
-            @Override
-            public String resolveCommand(String command) {
-                return Shell.resolve(session, command);
-            }
-            @Override
-            public String commandName(String command) {
-                int idx = command.indexOf(':');
-                return idx >= 0 ? command.substring(idx + 1) : command;
-            }
-            @Override
-            public Object evaluate(LineReader reader, ParsedLine line, String func) throws
Exception {
-                session.put(Shell.VAR_COMMAND_LINE, line);
-                return session.execute(func);
-            }
-        };
-        Completer builtinCompleter = new org.jline.builtins.Completers.Completer(env);
+        Completer builtinCompleter = createBuiltinCompleter();
         CommandsCompleter commandsCompleter = new CommandsCompleter(factory, this);
+        Completer completer =  (rdr, line, candidates) -> {
+            builtinCompleter.complete(rdr, line, candidates);
+            commandsCompleter.complete(rdr, line, candidates);
+        };
 
         // Console reader
         reader = LineReaderBuilder.builder()
@@ -178,10 +158,7 @@ public class ConsoleSessionImpl implements Session {
                     .variables(((CommandSessionImpl) session).getVariables())
                     .highlighter(new org.apache.felix.gogo.jline.Highlighter(session))
                     .parser(new KarafParser(this))
-                    .completer((rdr, line, candidates) -> {
-                        builtinCompleter.complete(rdr, line, candidates);
-                        commandsCompleter.complete(rdr, line, candidates);
-                    })
+                    .completer(completer)
                     .build();
 
         // History
@@ -235,6 +212,34 @@ public class ConsoleSessionImpl implements Session {
 
     }
 
+    private Completer createBuiltinCompleter() {
+        Completers.CompletionEnvironment env = new Completers.CompletionEnvironment() {
+            @Override
+            public Map<String, List<Completers.CompletionData>> getCompletions()
{
+                return Shell.getCompletions(session);
+            }
+            @Override
+            public Set<String> getCommands() {
+                return Shell.getCommands(session);
+            }
+            @Override
+            public String resolveCommand(String command) {
+                return Shell.resolve(session, command);
+            }
+            @Override
+            public String commandName(String command) {
+                int idx = command.indexOf(':');
+                return idx >= 0 ? command.substring(idx + 1) : command;
+            }
+            @Override
+            public Object evaluate(LineReader reader, ParsedLine line, String func) throws
Exception {
+                session.put(Shell.VAR_COMMAND_LINE, line);
+                return session.execute(func);
+            }
+        };
+        return new org.jline.builtins.Completers.Completer(env);
+    }
+
     /**
      * Subclasses can override to use a different history file.
      *


Mime
View raw message