use fixed sized lengths for dircounts

Related #19
This commit is contained in:
Gokcehan 2018-02-10 19:37:37 +03:00
parent 55ef28b4c7
commit 9fb16f78e0

25
ui.go
View File

@ -3,6 +3,7 @@ package main
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"io"
"log" "log"
"os" "os"
"path/filepath" "path/filepath"
@ -339,21 +340,27 @@ func (win *win) printDir(dir *dir, marks map[string]int, saves map[string]bool)
if f.count == -1 { if f.count == -1 {
d, err := os.Open(path) d, err := os.Open(path)
if err != nil { if err != nil {
log.Printf("opening dir to read count: %s", err) f.count = -2
continue
} }
names, err := d.Readdirnames(-1) names, err := d.Readdirnames(1000)
d.Close() d.Close()
if err != nil { if names == nil && err != io.EOF {
log.Printf("reading dir count: %s", err) f.count = -2
continue } 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": case "time":
info = fmt.Sprintf("%s %12s", info, f.ModTime().Format("Jan _2 15:04")) info = fmt.Sprintf("%s %12s", info, f.ModTime().Format("Jan _2 15:04"))
default: default: