From 9fb16f78e0d8902a0fbeb01c642eadcdb8b6f4bc Mon Sep 17 00:00:00 2001 From: Gokcehan Date: Sat, 10 Feb 2018 19:37:37 +0300 Subject: [PATCH] use fixed sized lengths for dircounts Related #19 --- ui.go | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/ui.go b/ui.go index 44aa5e3..11ea4b4 100644 --- a/ui.go +++ b/ui.go @@ -3,6 +3,7 @@ package main import ( "bytes" "fmt" + "io" "log" "os" "path/filepath" @@ -339,21 +340,27 @@ func (win *win) printDir(dir *dir, marks map[string]int, saves map[string]bool) if f.count == -1 { d, err := os.Open(path) if err != nil { - log.Printf("opening dir to read count: %s", err) - continue + f.count = -2 } - names, err := d.Readdirnames(-1) + names, err := d.Readdirnames(1000) d.Close() - if err != nil { - log.Printf("reading dir count: %s", err) - continue + if names == nil && err != io.EOF { + f.count = -2 + } else { + f.count = len(names) } - - f.count = len(names) } - info = fmt.Sprintf("%s %d", info, f.count) + + switch { + case f.count < 0: + info = fmt.Sprintf("%s ?", info) + case f.count < 1000: + info = fmt.Sprintf("%s %4d", info, f.count) + default: + info = fmt.Sprintf("%s 999+", info) + } case "time": info = fmt.Sprintf("%s %12s", info, f.ModTime().Format("Jan _2 15:04")) default: