geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r411702 - in /geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell: InteractiveShell.java Shell.java console/InteractiveConsole.java
Date Mon, 05 Jun 2006 07:42:58 GMT
Author: jdillon
Date: Mon Jun  5 00:42:57 2006
New Revision: 411702

URL: http://svn.apache.org/viewvc?rev=411702&view=rev
Log:
Hooked up semi-functional console tab completion when using JLine

Modified:
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/InteractiveShell.java
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/Shell.java
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/InteractiveConsole.java

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/InteractiveShell.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/InteractiveShell.java?rev=411702&r1=411701&r2=411702&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/InteractiveShell.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/InteractiveShell.java
Mon Jun  5 00:42:57 2006
@@ -18,11 +18,16 @@
 
 import org.apache.geronimo.gshell.console.InteractiveConsole;
 import org.apache.geronimo.gshell.console.Console;
+import org.apache.geronimo.gshell.console.JLineConsole;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
 import java.io.IOException;
 
+import jline.ConsoleReader;
+import jline.SimpleCompletor;
+import jline.CandidateListCompletionHandler;
+
 /**
  * Provides the user-interaction bits for Shell.
  *
@@ -38,16 +43,16 @@
     //       Seems like that is what we are doing so far anyways (sub-classing that is)
     //
 
-    public InteractiveShell(final Console console, final Shell gshell) throws IOException
{
+    public InteractiveShell(final Console console, final Shell shell) throws IOException
{
         super(console,
             new InteractiveConsole.Executor() {
                 public Result execute(final String line) throws Exception {
                     assert line != null;
 
                     // Execute unless the line is just blank
-                    if (!line.trim().equals("")) {
+                    if (line.trim().length() != 0) {
                         try {
-                            gshell.execute(line);
+                            shell.execute(line);
                         }
                         catch (ExitNotification n) {
                             return Result.STOP;
@@ -66,5 +71,20 @@
                     return "> ";
                 }
             });
+
+        // Add a command completer of we are using JLine
+        if (console instanceof JLineConsole) {
+            ConsoleReader jline = ((JLineConsole)console).getReader();
+
+            //
+            // TODO: Figure out why this does not work!!!!
+            //
+            jline.setCompletionHandler(new CandidateListCompletionHandler());
+
+            String[] commands = (String[])shell.getCommandManager().commandNames().toArray(new
String[0]);
+
+            SimpleCompletor c = new SimpleCompletor(commands);
+            jline.addCompletor(c);
+        }
     }
 }

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/Shell.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/Shell.java?rev=411702&r1=411701&r2=411702&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/Shell.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/Shell.java
Mon Jun  5 00:42:57 2006
@@ -91,6 +91,10 @@
         return io;
     }
 
+    public CommandManager getCommandManager() {
+        return commandManager;
+    }
+
     public int execute(final String commandLine) throws Exception {
         assert commandLine != null;
 

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/InteractiveConsole.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/InteractiveConsole.java?rev=411702&r1=411701&r2=411702&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/InteractiveConsole.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/InteractiveConsole.java
Mon Jun  5 00:42:57 2006
@@ -110,7 +110,7 @@
         boolean debug = log.isDebugEnabled();
         String line;
 
-        while ((line = console.readLine(prompter.getPrompt())) != null) {
+        while ((line = console.readLine(doGetPrompt())) != null) {
             if (debug) {
                 log.debug("Read line: " + line);
 
@@ -130,7 +130,7 @@
                 log.debug("     "  + idx);
             }
 
-            Executor.Result result = executor.execute(line);
+            Executor.Result result = doExecute(line);
 
             // Allow executor to request that the loop stop
             if (result == Executor.Result.STOP) {
@@ -152,6 +152,14 @@
         //       Use-case is that Shell might want to disallow and print a "use exit command",
         //       but Script interp wants this to exit and return control to Shell.
         //
+    }
+
+    protected Executor.Result doExecute(final String line) throws Exception {
+        return executor.execute(line);
+    }
+
+    protected String doGetPrompt() {
+        return prompter.getPrompt();
     }
 
     //



Mime
View raw message