felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r804956 - /felix/trunk/karaf/gshell/gshell-console/src/main/java/org/apache/felix/karaf/gshell/console/jline/Console.java
Date Mon, 17 Aug 2009 12:51:48 GMT
Author: gnodet
Date: Mon Aug 17 12:51:48 2009
New Revision: 804956

URL: http://svn.apache.org/viewvc?rev=804956&view=rev
Log:
Use a more simple mechanism for retrieving the prompt instead of evaluating a command

Modified:
    felix/trunk/karaf/gshell/gshell-console/src/main/java/org/apache/felix/karaf/gshell/console/jline/Console.java

Modified: felix/trunk/karaf/gshell/gshell-console/src/main/java/org/apache/felix/karaf/gshell/console/jline/Console.java
URL: http://svn.apache.org/viewvc/felix/trunk/karaf/gshell/gshell-console/src/main/java/org/apache/felix/karaf/gshell/console/jline/Console.java?rev=804956&r1=804955&r2=804956&view=diff
==============================================================================
--- felix/trunk/karaf/gshell/gshell-console/src/main/java/org/apache/felix/karaf/gshell/console/jline/Console.java
(original)
+++ felix/trunk/karaf/gshell/gshell-console/src/main/java/org/apache/felix/karaf/gshell/console/jline/Console.java
Mon Aug 17 12:51:48 2009
@@ -24,6 +24,8 @@
 import java.io.PrintStream;
 import java.io.PrintWriter;
 import java.util.Properties;
+import java.util.regex.Pattern;
+import java.util.regex.Matcher;
 import java.util.concurrent.ArrayBlockingQueue;
 import java.util.concurrent.BlockingQueue;
 
@@ -41,8 +43,7 @@
 {
 
     public static final String PROMPT = "PROMPT";
-    public static final String DEFAULT_PROMPT =
-             "\"\u001B\\[1m${USER}\u001B\\[0m@${APPLICATION}> \"";
+    public static final String DEFAULT_PROMPT = "\u001B[1m${USER}\u001B[0m@${APPLICATION}>
";
 
     private CommandSession session;
     private ConsoleReader reader;
@@ -174,9 +175,13 @@
             } catch (Throwable t) {
                 prompt = DEFAULT_PROMPT;
             }
-            Object v = session.execute(prompt);
-            if (v != null) {
-                prompt = v.toString();
+            Matcher matcher = Pattern.compile("\\$\\{([^}]+)\\}").matcher(prompt);
+            while (matcher.find()) {
+                Object rep = session.get(matcher.group(1));
+                if (rep != null) {
+                    prompt = prompt.replace(matcher.group(0), rep.toString());
+                    matcher.reset(prompt);
+                }
             }
             return prompt;
         } catch (Throwable t) {



Mime
View raw message