You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by gn...@apache.org on 2015/02/20 11:26:10 UTC

[3/3] karaf git commit: [KARAF-3545] The bundle:list command should display ellipsis when displaying long bundle locations

[KARAF-3545] The bundle:list command should display ellipsis when displaying long bundle locations

Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/47414d98
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/47414d98
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/47414d98

Branch: refs/heads/master
Commit: 47414d989d9c055aa4da9d2a8b18a119852f14bc
Parents: f621963
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Fri Feb 20 11:06:35 2015 +0100
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Fri Feb 20 11:06:35 2015 +0100

----------------------------------------------------------------------
 .../org/apache/karaf/bundle/command/List.java   | 39 +++++++++++++++++++-
 1 file changed, 37 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/47414d98/bundle/core/src/main/java/org/apache/karaf/bundle/command/List.java
----------------------------------------------------------------------
diff --git a/bundle/core/src/main/java/org/apache/karaf/bundle/command/List.java b/bundle/core/src/main/java/org/apache/karaf/bundle/command/List.java
index 14b2523..82119c0 100644
--- a/bundle/core/src/main/java/org/apache/karaf/bundle/command/List.java
+++ b/bundle/core/src/main/java/org/apache/karaf/bundle/command/List.java
@@ -24,6 +24,8 @@ import org.apache.karaf.shell.api.action.Command;
 import org.apache.karaf.shell.api.action.Option;
 import org.apache.karaf.shell.api.action.lifecycle.Reference;
 import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.apache.karaf.shell.api.console.Terminal;
+import org.apache.karaf.shell.support.table.Col;
 import org.apache.karaf.shell.support.table.ShellTable;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
@@ -48,18 +50,28 @@ public class List extends BundlesCommand {
     @Option(name = "--no-format", description = "Disable table rendered output", required = false, multiValued = false)
     boolean noFormat;
 
+    @Option(name = "--no-ellipsis")
+    boolean noEllipsis;
+
     @Reference
     BundleContext bundleContext;
 
     @Reference
     BundleService bundleService;
 
+    @Reference
+    Terminal terminal;
+
     @Override
     protected void executeOnBundle(Bundle bundle) throws Exception {
     }
 
     @Override
     protected Object doExecute(java.util.List<Bundle> bundles) throws Exception {
+        if (noFormat) {
+            noEllipsis = true;
+        }
+
         determineBundleLevelThreshold();
         
         // Display active start level.
@@ -69,12 +81,35 @@ public class List extends BundlesCommand {
         }
 
         ShellTable table = new ShellTable();
+        if (!noEllipsis && showLocation && terminal != null && terminal.getWidth() > 0) {
+            table.size(terminal.getWidth());
+        }
         table.column("ID").alignRight();
         table.column("State");
         table.column("Lvl").alignRight();
         table.column("Version");
-        table.column(getNameHeader());
-        
+        table.column(new Col(getNameHeader()) {
+            @Override
+            protected String cut(String value, int size) {
+                if (showLocation && value.length() > size) {
+                    String[] parts = value.split("/");
+                    String cut = "";
+                    int c = parts[0].length() + 4;
+                    for (int idx = parts.length - 1; idx > 0; idx--) {
+                        if (cut.length() + c + parts[idx].length() + 1 < size) {
+                            cut = "/" + parts[idx] + cut;
+                        } else {
+                            break;
+                        }
+                    }
+                    cut = parts[0] + "/..." + cut;
+                    return cut;
+                } else {
+                    return super.cut(value, size);
+                }
+            }
+        });
+
         for (Bundle bundle : bundles) {
             BundleInfo info = this.bundleService.getInfo(bundle);
             if (info.getStartLevel() >= bundleLevelThreshold) {