forked from TrueCloudLab/rclone
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:
parent
127f0fc64c
commit
f89ff3872d
1 changed files with 49 additions and 32 deletions
|
@ -71,6 +71,7 @@ func helpText() (tr []string) {
|
||||||
" ←,h to return",
|
" ←,h to return",
|
||||||
" c toggle counts",
|
" c toggle counts",
|
||||||
" g toggle graph",
|
" g toggle graph",
|
||||||
|
" a toggle average size in directory",
|
||||||
" n,s,C,A sort by name,size,count,average size",
|
" n,s,C,A sort by name,size,count,average size",
|
||||||
" d delete file/directory",
|
" d delete file/directory",
|
||||||
}
|
}
|
||||||
|
@ -105,6 +106,7 @@ type UI struct {
|
||||||
listing bool // whether listing is in progress
|
listing bool // whether listing is in progress
|
||||||
showGraph bool // toggle showing graph
|
showGraph bool // toggle showing graph
|
||||||
showCounts bool // toggle showing counts
|
showCounts bool // toggle showing counts
|
||||||
|
showDirAverageSize bool // toggle average size
|
||||||
sortByName int8 // +1 for normal, 0 for off, -1 for reverse
|
sortByName int8 // +1 for normal, 0 for off, -1 for reverse
|
||||||
sortBySize int8
|
sortBySize int8
|
||||||
sortByCount int8
|
sortByCount int8
|
||||||
|
@ -346,6 +348,18 @@ func (u *UI) Draw() error {
|
||||||
extras += " "
|
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 {
|
if u.showGraph {
|
||||||
bars := (size + perBar/2 - 1) / perBar
|
bars := (size + perBar/2 - 1) / perBar
|
||||||
|
@ -667,6 +681,7 @@ func NewUI(f fs.Fs) *UI {
|
||||||
fsName: f.Name() + ":" + f.Root(),
|
fsName: f.Name() + ":" + f.Root(),
|
||||||
showGraph: true,
|
showGraph: true,
|
||||||
showCounts: false,
|
showCounts: false,
|
||||||
|
showDirAverageSize: false,
|
||||||
sortByName: 0, // +1 for normal, 0 for off, -1 for reverse
|
sortByName: 0, // +1 for normal, 0 for off, -1 for reverse
|
||||||
sortBySize: 1,
|
sortBySize: 1,
|
||||||
sortByCount: 0,
|
sortByCount: 0,
|
||||||
|
@ -758,6 +773,8 @@ outer:
|
||||||
u.showCounts = !u.showCounts
|
u.showCounts = !u.showCounts
|
||||||
case 'g':
|
case 'g':
|
||||||
u.showGraph = !u.showGraph
|
u.showGraph = !u.showGraph
|
||||||
|
case 'a':
|
||||||
|
u.showDirAverageSize = !u.showDirAverageSize
|
||||||
case 'n':
|
case 'n':
|
||||||
u.toggleSort(&u.sortByName)
|
u.toggleSort(&u.sortByName)
|
||||||
case 's':
|
case 's':
|
||||||
|
|
Loading…
Reference in a new issue