geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r700099 - /geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/java/org/apache/geronimo/gshell/commands/vfs/ListDirectoryAction.java
Date Mon, 29 Sep 2008 12:32:50 GMT
Author: jdillon
Date: Mon Sep 29 05:32:50 2008
New Revision: 700099

URL: http://svn.apache.org/viewvc?rev=700099&view=rev
Log:
Set the default ls style to that one might expect, column view.

Modified:
    geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/java/org/apache/geronimo/gshell/commands/vfs/ListDirectoryAction.java

Modified: geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/java/org/apache/geronimo/gshell/commands/vfs/ListDirectoryAction.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/java/org/apache/geronimo/gshell/commands/vfs/ListDirectoryAction.java?rev=700099&r1=700098&r2=700099&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/java/org/apache/geronimo/gshell/commands/vfs/ListDirectoryAction.java
(original)
+++ geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/java/org/apache/geronimo/gshell/commands/vfs/ListDirectoryAction.java
Mon Sep 29 05:32:50 2008
@@ -33,6 +33,12 @@
 
 import java.text.DateFormat;
 import java.util.Date;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.io.PrintWriter;
+
+import jline.ConsoleReader;
 
 /**
  * List the contents of a file or directory.
@@ -45,6 +51,10 @@
     @Argument
     private String path;
 
+    //
+    // TODO: Add -l support
+    //
+
     @Option(name="-a")
     private boolean includeHidden = false;
 
@@ -64,7 +74,7 @@
         }
 
         if (file.getType() == FileType.FOLDER) {
-            listChildren(io, file, recursive, "");
+            listChildren(io, file);
         }
         else {
             io.info("{}", file.getName());
@@ -80,10 +90,9 @@
         return Result.SUCCESS;
     }
 
-    private void listChildren(final IO io, final FileObject dir, final boolean recursive,
final String prefix) throws FileSystemException {
+    private void listChildren(final IO io, final FileObject dir) throws Exception {
         assert io != null;
         assert dir != null;
-        assert prefix != null;
 
         FileObject[] files;
 
@@ -107,19 +116,41 @@
             files = dir.findFiles(new FileFilterSelector(filter));
         }
 
+        //
+        // FIXME: Need to have the framework provide a reader, which is initialized correctly...
or make this accessible via IO?
+        //
+
+        ConsoleReader reader = new ConsoleReader(
+                io.inputStream,
+                new PrintWriter(io.outputStream, true),
+                null, // bindings
+                io.getTerminal());
+        
+        reader.setUsePagination(false);
+
+        List<String> names = new ArrayList<String>(files.length);
+        List<FileObject> dirs = new LinkedList<FileObject>();
+
         for (FileObject file : files) {
-            io.out.print(prefix);
-            io.out.print(file.getName().getBaseName());
+            names.add(file.getName().getBaseName());
 
             if (file.getType() == FileType.FOLDER) {
-                io.out.println("/");
+                names.add(file.getName().getBaseName() + "/");
 
                 if (recursive) {
-                    listChildren(io, file, recursive, prefix + "    ");
+                    dirs.add(file);
                 }
             }
-            else {
+        }
+
+        reader.printColumns(names);
+        
+        if (!dirs.isEmpty()) {
+            for (FileObject subdir : dirs) {
                 io.out.println();
+                io.out.print(subdir.getName().getBaseName());
+                io.out.print(":");
+                listChildren(io, subdir);
             }
         }
     }



Mime
View raw message