Anonymous avatar Anonymous committed 9d21cea

added plus sign as a dirflag

Comments (0)

Files changed (1)

 	"strings"
 	"sort"
 	"flag"
+	//	"bytes"
 
 	"goplan9.googlecode.com/hg/plan9"
 	"goplan9.googlecode.com/hg/plan9/acme"
 var PLAN9 = os.Getenv("PLAN9")
 
 const NBUF = 512
+const dirflag = "+ "
 
 func usage() {
 	fmt.Fprintf(os.Stderr, "usage: xplor [path] \n")
 	return printDirContents(root, 0)
 }
 
-func printDirContents(path string, depth int) os.Error {
-	currentDir, err := os.Open(path, os.O_RDONLY, 0644)
+func printDirContents(dirpath string, depth int) os.Error {
+	currentDir, err := os.Open(dirpath, os.O_RDONLY, 0644)
 	if err != nil {
 		return err
 	}
 		indents = indents + INDENT
 	}
 	for _, v := range names {
-		w.Write("data", []byte(indents+v+"\n"))
+		// we want to be fast so we assume (for the printing) that any name containing a dot is not a dir
+		if !strings.Contains(v, ".") {
+			fullpath := path.Join(dirpath, v)
+			fi, err := os.Lstat(fullpath)
+			if err != nil {
+				return err
+			}
+			if fi.IsDirectory() {
+				w.Write("data", []byte(dirflag+indents+v+"\n"))
+			}
+		} else {
+			w.Write("data", []byte("  "+indents+v+"\n"))
+		}
 	}
 
 	//lame trick for now to dodge the out of range issue, until my address-foo gets better
 	}
 	n, err := w.Read("xdata", b)
 
-	return b[0 : n-1], err
+	// remove dirflag, if any
+	if n < 2 {
+		return b[0 : n-1], err
+	}
+	return b[2 : n-1], err
 }
 
 func getDepth(line []byte) (depth int, trimedline string) {
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.