You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jd...@apache.org on 2007/09/08 22:43:53 UTC

svn commit: r573906 - in /geronimo/sandbox/gshell/trunk: gshell-cli/ gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/ gshell-commands/gshell-builtins/ gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/ g...

Author: jdillon
Date: Sat Sep  8 13:43:52 2007
New Revision: 573906

URL: http://svn.apache.org/viewvc?rev=573906&view=rev
Log:
Fancy up the prompt and help display with some ansi

Modified:
    geronimo/sandbox/gshell/trunk/gshell-cli/pom.xml
    geronimo/sandbox/gshell/trunk/gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/Main.java
    geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/pom.xml
    geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/ExitCommand.java
    geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/HelpCommand.java
    geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/SetCommand.java
    geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/SourceCommand.java
    geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/UnsetCommand.java
    geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/src/main/resources/META-INF/gshell/commands.xml
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/LayoutManager.java
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/LayoutManagerImpl.java

Modified: geronimo/sandbox/gshell/trunk/gshell-cli/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-cli/pom.xml?rev=573906&r1=573905&r2=573906&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-cli/pom.xml (original)
+++ geronimo/sandbox/gshell/trunk/gshell-cli/pom.xml Sat Sep  8 13:43:52 2007
@@ -40,6 +40,12 @@
     <dependencies>
         <dependency>
             <groupId>org.apache.geronimo.gshell</groupId>
+            <artifactId>gshell-ansi</artifactId>
+            <version>${pom.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.geronimo.gshell</groupId>
             <artifactId>gshell-core</artifactId>
             <version>${pom.version}</version>
         </dependency>

Modified: geronimo/sandbox/gshell/trunk/gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/Main.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/Main.java?rev=573906&r1=573905&r2=573906&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/Main.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/Main.java Sat Sep  8 13:43:52 2007
@@ -21,10 +21,12 @@
 
 import java.util.ArrayList;
 import java.util.List;
+import java.io.IOException;
 
 import jline.Terminal;
 import org.apache.geronimo.gshell.ExitNotification;
 import org.apache.geronimo.gshell.Shell;
+import org.apache.geronimo.gshell.ansi.Renderer;
 import org.apache.geronimo.gshell.clp.Argument;
 import org.apache.geronimo.gshell.clp.CommandLineProcessor;
 import org.apache.geronimo.gshell.clp.Option;
@@ -229,6 +231,15 @@
 
             JLineConsole runner = new JLineConsole(executor, io);
 
+            runner.setPrompter(new Console.Prompter() {
+                Renderer renderer = new Renderer();
+
+                public String prompt() {
+                    return renderer.render("@|bold gsh| > ");
+                }
+            });
+
+
             runner.setErrorHandler(new Console.ErrorHandler() {
                 public Result handleError(Throwable error) {
                     // Must use string concat here to get the error passed in as a Throwable for rendering
@@ -274,3 +285,4 @@
         main(args, new ClassWorld("gshell.legacy", Thread.currentThread().getContextClassLoader()));
     }
 }
+

Modified: geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/pom.xml?rev=573906&r1=573905&r2=573906&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/pom.xml (original)
+++ geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/pom.xml Sat Sep  8 13:43:52 2007
@@ -40,6 +40,12 @@
     <dependencies>
         <dependency>
             <groupId>org.apache.geronimo.gshell</groupId>
+            <artifactId>gshell-ansi</artifactId>
+            <version>${pom.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.geronimo.gshell</groupId>
             <artifactId>gshell-core</artifactId>
             <version>${pom.version}</version>
         </dependency>

Modified: geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/ExitCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/ExitCommand.java?rev=573906&r1=573905&r2=573906&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/ExitCommand.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/ExitCommand.java Sat Sep  8 13:43:52 2007
@@ -29,7 +29,7 @@
  *
  * @version $Rev$ $Date$
  */
-@CommandComponent(id="exit")
+@CommandComponent(id="exit", description="Exit the shell")
 public class ExitCommand
     extends CommandSupport
 {

Modified: geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/HelpCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/HelpCommand.java?rev=573906&r1=573905&r2=573906&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/HelpCommand.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/HelpCommand.java Sat Sep  8 13:43:52 2007
@@ -21,19 +21,22 @@
 
 import java.util.Collection;
 
+import org.apache.geronimo.gshell.ansi.Code;
+import org.apache.geronimo.gshell.ansi.Renderer;
 import org.apache.geronimo.gshell.command.CommandSupport;
 import org.apache.geronimo.gshell.command.annotation.CommandComponent;
 import org.apache.geronimo.gshell.command.descriptor.CommandDescriptor;
 import org.apache.geronimo.gshell.layout.LayoutManager;
 import org.apache.geronimo.gshell.plugin.PluginCollector;
 import org.codehaus.plexus.component.annotations.Requirement;
+import org.codehaus.plexus.util.StringUtils;
 
 /**
  * Display help
  *
  * @version $Rev$ $Date$
  */
-@CommandComponent(id="help")
+@CommandComponent(id="help", description="Show command help")
 public class HelpCommand
     extends CommandSupport
 {
@@ -43,24 +46,62 @@
     @Requirement
     private LayoutManager layoutManager;
 
+    private Renderer renderer = new Renderer();
+
     protected Object doExecute() throws Exception {
         assert pluginCollector != null;
         assert layoutManager != null;
 
+        //
+        // TODO: Get this from branding theme thingy
+        //
+
+        io.out.println();
+        io.out.println("For information about Apache Geronimo, visit:");
+        io.out.println("    http://geronimo.apache.org ");
+        io.out.println();
+
         io.out.println("Available commands:");
 
         Collection<CommandDescriptor> commands = pluginCollector.getCommandDescriptors();
 
+        // Figure out the maximum length of a command name
+        int maxNameLen = 0;
+        for (CommandDescriptor desc : commands) {
+            if (desc.getId().length() > maxNameLen) {
+                maxNameLen = desc.getId().length();
+            }
+        }
+
         //
         // TODO: Need to ask the LayoutManager...
         //
 
-        for (CommandDescriptor desc : commands) {
+        for (CommandDescriptor d : commands) {
+            // Hide commands if they don't have descriptions
+            String name = d.getId();
+            name = StringUtils.rightPad(name, maxNameLen);
+
             io.out.print("  ");
-            io.out.print(desc.getId());
-            io.out.println();
+            io.out.print(renderer.render(Renderer.encode(name, Code.BOLD)));
+
+            String desc = d.getDescription();
+
+            if (desc != null) {
+                io.out.print("  ");
+                io.out.println(desc);
+            }
+            else {
+                io.out.println();
+            }
         }
-        
+
+        /*
+        io.out.println();
+        io.out.println("For help on a specific command type:");
+        io.out.println("    help <command>");
+        */
+
         io.out.println();
 
         return SUCCESS;

Modified: geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/SetCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/SetCommand.java?rev=573906&r1=573905&r2=573906&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/SetCommand.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/SetCommand.java Sat Sep  8 13:43:52 2007
@@ -35,7 +35,7 @@
  *
  * @version $Rev$ $Date$
  */
-@CommandComponent(id="set")
+@CommandComponent(id="set", description="Set a variable")
 public class SetCommand
     extends CommandSupport
 {

Modified: geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/SourceCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/SourceCommand.java?rev=573906&r1=573905&r2=573906&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/SourceCommand.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/SourceCommand.java Sat Sep  8 13:43:52 2007
@@ -38,7 +38,7 @@
  *
  * @version $Rev$ $Date$
  */
-@CommandComponent(id="source")
+@CommandComponent(id="source", description="Load a file/url into the current shell")
 public class SourceCommand
     extends CommandSupport
 {

Modified: geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/UnsetCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/UnsetCommand.java?rev=573906&r1=573905&r2=573906&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/UnsetCommand.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/UnsetCommand.java Sat Sep  8 13:43:52 2007
@@ -33,7 +33,7 @@
  *
  * @version $Rev$ $Date$
  */
-@CommandComponent(id="unset")
+@CommandComponent(id="unset", description="Unset a variable")
 public class UnsetCommand
     extends CommandSupport
 {

Modified: geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/src/main/resources/META-INF/gshell/commands.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/src/main/resources/META-INF/gshell/commands.xml?rev=573906&r1=573905&r2=573906&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/src/main/resources/META-INF/gshell/commands.xml (original)
+++ geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/src/main/resources/META-INF/gshell/commands.xml Sat Sep  8 13:43:52 2007
@@ -6,11 +6,13 @@
         <command>
             <id>exit</id>
             <implementation>org.apache.geronimo.gshell.commands.builtins.ExitCommand</implementation>
+            <description>Exit the shell</description>
         </command>
         
         <command>
             <id>help</id>
             <implementation>org.apache.geronimo.gshell.commands.builtins.HelpCommand</implementation>
+            <description>Display help</description>
             <requirements>
                 <requirement>
                     <role>org.apache.geronimo.gshell.plugin.PluginCollector</role>
@@ -26,11 +28,13 @@
         <command>
             <id>set</id>
             <implementation>org.apache.geronimo.gshell.commands.builtins.SetCommand</implementation>
+            <description>Set a variable</description>
         </command>
         
         <command>
             <id>source</id>
             <implementation>org.apache.geronimo.gshell.commands.builtins.SourceCommand</implementation>
+            <description>Load a file or url into the shell</description>
             <requirements>
                 <requirement>
                     <role>org.apache.geronimo.gshell.Shell</role>
@@ -42,6 +46,7 @@
         <command>
             <id>unset</id>
             <implementation>org.apache.geronimo.gshell.commands.builtins.UnsetCommand</implementation>
+            <description>Unset a variable</description>
         </command>
     </commands>
 </command-set>

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/LayoutManager.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/LayoutManager.java?rev=573906&r1=573905&r2=573906&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/LayoutManager.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/LayoutManager.java Sat Sep  8 13:43:52 2007
@@ -29,7 +29,13 @@
  */
 public interface LayoutManager
 {
+    /**
+     * Returns the currently loaded layout; never null.
+     */
     Layout getLayout();
 
+    /**
+     * Find the command descriptor for the given path, or null if not found.
+     */
     CommandDescriptor find(String path);
 }

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/LayoutManagerImpl.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/LayoutManagerImpl.java?rev=573906&r1=573905&r2=573906&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/LayoutManagerImpl.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/LayoutManagerImpl.java Sat Sep  8 13:43:52 2007
@@ -59,7 +59,8 @@
         assert info != null;
 
         //
-        // TODO: Move to a layout loader to abstract how this is loaded and allow for better configuration
+        // TODO: Move to a layout loader to abstract how this is loaded and allow for better configuration...
+        //       may be able to use a LayoutFactory component here...
         //
         
         URL url;