felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r910220 - in /felix/trunk/karaf/shell: commands/src/main/java/org/apache/felix/karaf/shell/commands/ commands/src/main/resources/OSGI-INF/blueprint/ console/src/main/java/org/apache/felix/karaf/shell/console/jline/
Date Mon, 15 Feb 2010 14:10:50 GMT
Author: gnodet
Date: Mon Feb 15 14:10:50 2010
New Revision: 910220

URL: http://svn.apache.org/viewvc?rev=910220&view=rev
Log:
FELIX-2074: Bring back the history command

Modified:
    felix/trunk/karaf/shell/commands/src/main/java/org/apache/felix/karaf/shell/commands/HistoryAction.java
    felix/trunk/karaf/shell/commands/src/main/resources/OSGI-INF/blueprint/shell-commands.xml
    felix/trunk/karaf/shell/console/src/main/java/org/apache/felix/karaf/shell/console/jline/Console.java

Modified: felix/trunk/karaf/shell/commands/src/main/java/org/apache/felix/karaf/shell/commands/HistoryAction.java
URL: http://svn.apache.org/viewvc/felix/trunk/karaf/shell/commands/src/main/java/org/apache/felix/karaf/shell/commands/HistoryAction.java?rev=910220&r1=910219&r2=910220&view=diff
==============================================================================
--- felix/trunk/karaf/shell/commands/src/main/java/org/apache/felix/karaf/shell/commands/HistoryAction.java
(original)
+++ felix/trunk/karaf/shell/commands/src/main/java/org/apache/felix/karaf/shell/commands/HistoryAction.java
Mon Feb 15 14:10:50 2010
@@ -16,8 +16,35 @@
  */
 package org.apache.felix.karaf.shell.commands;
 
+import java.util.List;
+
+import jline.History;
+import org.apache.felix.gogo.commands.Command;
+import org.apache.felix.karaf.shell.console.OsgiCommandSupport;
+import org.fusesource.jansi.Ansi;
+
 /**
- * TODO
+ * History command
  */
-public class HistoryAction {
+@Command(scope = "shell", name="history", description="Prints command history")
+public class HistoryAction extends OsgiCommandSupport {
+
+    @Override
+    protected Object doExecute() throws Exception {
+        History history = (History) session.get(".jline.history");
+        List<String> elements = history.getHistoryList();
+
+        int i = 0;
+        for (String element : elements) {
+            System.out.println(
+                    Ansi.ansi()
+                        .a("  ")
+                        .a(Ansi.Attribute.INTENSITY_BOLD).render("%3d", i).a(Ansi.Attribute.INTENSITY_BOLD_OFF)
+                        .a("  ")
+                        .a(element)
+                        .toString());
+            i++;
+        }
+        return null;
+    }
 }

Modified: felix/trunk/karaf/shell/commands/src/main/resources/OSGI-INF/blueprint/shell-commands.xml
URL: http://svn.apache.org/viewvc/felix/trunk/karaf/shell/commands/src/main/resources/OSGI-INF/blueprint/shell-commands.xml?rev=910220&r1=910219&r2=910220&view=diff
==============================================================================
--- felix/trunk/karaf/shell/commands/src/main/resources/OSGI-INF/blueprint/shell-commands.xml
(original)
+++ felix/trunk/karaf/shell/commands/src/main/resources/OSGI-INF/blueprint/shell-commands.xml
Mon Feb 15 14:10:50 2010
@@ -35,11 +35,9 @@
         <command name="shell/grep">
             <action class="org.apache.felix.karaf.shell.commands.GrepAction"/>
         </command>
-        <!--
         <command name="shell/history">
             <action class="org.apache.felix.karaf.shell.commands.HistoryAction"/>
         </command>
-        -->
         <command name="shell/if">
             <action class="org.apache.felix.karaf.shell.commands.IfAction"/>
         </command>

Modified: felix/trunk/karaf/shell/console/src/main/java/org/apache/felix/karaf/shell/console/jline/Console.java
URL: http://svn.apache.org/viewvc/felix/trunk/karaf/shell/console/src/main/java/org/apache/felix/karaf/shell/console/jline/Console.java?rev=910220&r1=910219&r2=910220&view=diff
==============================================================================
--- felix/trunk/karaf/shell/console/src/main/java/org/apache/felix/karaf/shell/console/jline/Console.java
(original)
+++ felix/trunk/karaf/shell/console/src/main/java/org/apache/felix/karaf/shell/console/jline/Console.java
Mon Feb 15 14:10:50 2010
@@ -102,6 +102,7 @@
         File file = new File(System.getProperty("user.home"), ".karaf/karaf.history");
         file.getParentFile().mkdirs();
         reader.getHistory().setHistoryFile(file);
+        session.put(".jline.history", reader.getHistory());
         if (completer != null) {
             reader.addCompletor(
                 new CompleterAsCompletor(



Mime
View raw message