felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r1346792 - /felix/trunk/gogo/shell/src/main/java/org/apache/felix/gogo/shell/Console.java
Date Wed, 06 Jun 2012 08:57:30 GMT
Author: fmeschbe
Date: Wed Jun  6 08:57:30 2012
New Revision: 1346792

URL: http://svn.apache.org/viewvc?rev=1346792&view=rev
Log:
FELIX-3340 Allow the prompt to be a Function

Modified:
    felix/trunk/gogo/shell/src/main/java/org/apache/felix/gogo/shell/Console.java

Modified: felix/trunk/gogo/shell/src/main/java/org/apache/felix/gogo/shell/Console.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/shell/src/main/java/org/apache/felix/gogo/shell/Console.java?rev=1346792&r1=1346791&r2=1346792&view=diff
==============================================================================
--- felix/trunk/gogo/shell/src/main/java/org/apache/felix/gogo/shell/Console.java (original)
+++ felix/trunk/gogo/shell/src/main/java/org/apache/felix/gogo/shell/Console.java Wed Jun
 6 08:57:30 2012
@@ -21,8 +21,10 @@ package org.apache.felix.gogo.shell;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.PrintStream;
+
 import org.apache.felix.service.command.CommandSession;
 import org.apache.felix.service.command.Converter;
+import org.apache.felix.service.command.Function;
 
 public class Console implements Runnable
 {
@@ -46,13 +48,7 @@ public class Console implements Runnable
         {
             while (!quit)
             {
-                Object prompt = session.get("prompt");
-                if (prompt == null)
-                {
-                    prompt = "g! ";
-                }
-
-                CharSequence line = getLine(prompt.toString());
+                CharSequence line = getLine(getPrompt());
 
                 if (line == null)
                 {
@@ -118,6 +114,30 @@ public class Console implements Runnable
         }
     }
 
+    private String getPrompt()
+    {
+        Object prompt = session.get("prompt");
+        if (prompt instanceof Function)
+        {
+            try
+            {
+                prompt = ((Function) prompt).execute(session, null);
+            }
+            catch (Exception e)
+            {
+                out.println(prompt + ": " + e.getClass().getSimpleName() + ": " + e.getMessage());
+                prompt = null;
+            }
+        }
+
+        if (prompt == null)
+        {
+            prompt = "g! ";
+        }
+
+        return prompt.toString();
+    }
+
     private CharSequence getLine(String prompt) throws IOException
     {
         StringBuilder sb = new StringBuilder();



Mime
View raw message