sort files based on size

This commit is contained in:
Timon Ringwald 2022-08-03 21:28:45 +02:00
parent 4248994b75
commit 8eb4c0d173
3 changed files with 19 additions and 7 deletions

View File

@ -141,13 +141,6 @@ func (e *DirectoryEntry) SetRemovalMark(mark bool) {
for _, entry := range e.Entries() {
entry.SetRemovalMark(mark)
}
if e.Parent() != nil {
pentries := e.Parent().Entries()
sort.Slice(pentries, func(i, j int) bool {
return pentries[i].SizeModified() < pentries[j].SizeModified()
})
}
}
func (e *DirectoryEntry) RemovalMark() bool {
@ -166,6 +159,12 @@ func (e *DirectoryEntry) modifySize(modifier uint64) {
*e.modSize += modifier
if e.parent != nil {
e.parent.modifySize(modifier)
// recalculate order of parent entries
pentries := e.Parent().Entries()
sort.Slice(pentries, func(i, j int) bool {
return pentries[i].SizeModified() < pentries[j].SizeModified()
})
}
}

View File

@ -5,6 +5,7 @@ import (
"fmt"
"os"
"path/filepath"
"sort"
"strings"
)
@ -117,6 +118,12 @@ func (e *FileEntry) SetRemovalMark(mark bool) {
} else {
e.modifySize(*e.size)
}
// recalculate order of parent entries
pentries := e.Parent().Entries()
sort.Slice(pentries, func(i, j int) bool {
return pentries[i].SizeModified() < pentries[j].SizeModified()
})
}
func (e *FileEntry) RemovalMark() bool {

View File

@ -26,6 +26,12 @@ var (
IconTheme = flag.String("i", "unicode", "icon theme (currently supported: default, unicode, nerd)")
)
// FIXME sometimes sorting not applied after removing items
// TODO pwd command showing Current entry path and Root entry path in filesystem
// TODO arrow up -> last command (`stty -raw` necessary?). even better: rlwrap impl (see tsoding noq)
// TODO config file with preferred icon theme or read best icon theme from terminfo somehow
// TODO on exit: show deleted files in recursive tree (only deleted files and their parent directories)
// TODO autocomplete on TAB (see arrow up issue: raw necessary?)
func main() {
flag.Parse()
rootPath := flag.Arg(0)