From b218bc5bed99f04edf67c37f4fc1ec79bba5f03c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Pl=C3=A1nsk=C3=BD?= Date: Fri, 30 Oct 2020 16:54:59 +0100 Subject: [PATCH] ncdu: add empty folder flag into ncdu browser Implemented empty folder flag for ncdu browser interface. If there is empty folder in the list the flag e is prepended before size. If there is no empty folder this flag is ommited. It has the same behaviour as original ncdu browser. (https://dev.yorhel.nl/ncdu/man) --- cmd/ncdu/ncdu.go | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/cmd/ncdu/ncdu.go b/cmd/ncdu/ncdu.go index 4bc1d53e6..919506e7a 100644 --- a/cmd/ncdu/ncdu.go +++ b/cmd/ncdu/ncdu.go @@ -289,6 +289,20 @@ func (u *UI) biggestEntry() (biggest int64) { return } +// hasEmptyDir returns true if there is empty folder in current listing +func (u *UI) hasEmptyDir() bool { + if u.d == nil { + return false + } + for i := range u.entries { + _, count, isDir, _, _, _ := u.d.AttrI(u.sortPerm[i]) + if isDir && count == 0 { + return true + } + } + return false +} + // Draw the current screen func (u *UI) Draw() error { w, h := termbox.Size() @@ -319,6 +333,7 @@ func (u *UI) Draw() error { if perBar == 0 { perBar = 1 } + showEmptyDir := u.hasEmptyDir() dirPos := u.dirPosMap[u.path] for i, j := range u.sortPerm[dirPos.offset:] { entry := u.entries[j] @@ -373,6 +388,14 @@ func (u *UI) Draw() error { } } + emptyDir := "" + if showEmptyDir { + if isDir && count == 0 { + emptyDir = "e" + } else { + emptyDir = " " + } + } if u.showGraph { bars := (size + perBar/2 - 1) / perBar // clip if necessary - only happens during startup @@ -383,7 +406,7 @@ func (u *UI) Draw() error { } extras += "[" + graph[graphBars-bars:2*graphBars-bars] + "] " } - Linef(0, y, w, fg, bg, ' ', "%8v %s%c%s%s", fs.SizeSuffix(size), extras, mark, path.Base(entry.Remote()), message) + Linef(0, y, w, fg, bg, ' ', "%s %8v %s%c%s%s", emptyDir, fs.SizeSuffix(size), extras, mark, path.Base(entry.Remote()), message) y++ } }