ncdu: add toggle option for average size in directory - key 'a'

Add toggle option to show average size in directory. This toggle
function is for ncdu and is binded to key 'a'.
This commit is contained in:
Adam Plánský 2020-10-26 21:44:01 +01:00 committed by Nick Craig-Wood
parent 127f0fc64c
commit f89ff3872d
1 changed files with 49 additions and 32 deletions

View File

@ -71,6 +71,7 @@ func helpText() (tr []string) {
" ←,h to return",
" c toggle counts",
" g toggle graph",
" a toggle average size in directory",
" n,s,C,A sort by name,size,count,average size",
" d delete file/directory",
}
@ -105,6 +106,7 @@ type UI struct {
listing bool // whether listing is in progress
showGraph bool // toggle showing graph
showCounts bool // toggle showing counts
showDirAverageSize bool // toggle average size
sortByName int8 // +1 for normal, 0 for off, -1 for reverse
sortBySize int8
sortByCount int8
@ -346,6 +348,18 @@ func (u *UI) Draw() error {
extras += " "
}
}
var averageSize float64
if count > 0 {
averageSize = float64(size) / float64(count)
}
if u.showDirAverageSize {
if averageSize > 0 {
extras += fmt.Sprintf("%8v ", fs.SizeSuffix(int64(averageSize)))
} else {
extras += " "
}
}
if u.showGraph {
bars := (size + perBar/2 - 1) / perBar
@ -667,6 +681,7 @@ func NewUI(f fs.Fs) *UI {
fsName: f.Name() + ":" + f.Root(),
showGraph: true,
showCounts: false,
showDirAverageSize: false,
sortByName: 0, // +1 for normal, 0 for off, -1 for reverse
sortBySize: 1,
sortByCount: 0,
@ -758,6 +773,8 @@ outer:
u.showCounts = !u.showCounts
case 'g':
u.showGraph = !u.showGraph
case 'a':
u.showDirAverageSize = !u.showDirAverageSize
case 'n':
u.toggleSort(&u.sortByName)
case 's':