From 280b9ab7e42ca281231356b50bdcd634dcd71735 Mon Sep 17 00:00:00 2001 From: kivattt Date: Thu, 12 Sep 2024 06:55:01 +0200 Subject: [PATCH] Make faster by only updating screen every 250ms --- fssize.go | 8 ++++---- main.go | 11 ++++++++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/fssize.go b/fssize.go index a88e353..ca8eb0e 100644 --- a/fssize.go +++ b/fssize.go @@ -217,9 +217,9 @@ func (fssize *FSSize) walkDir(path string, d fs.DirEntry, walkDirFn fs.WalkDirFu fssize.folders = append(fssize.folders, File{path: path, sizeBytes: dirSize}) fssize.SortFiles(&fssize.folders) - if fssize.app != nil && fssize.currentTab == Folders { + /*if fssize.app != nil && fssize.currentTab == Folders { fssize.app.QueueUpdateDraw(func() {}) - } + }*/ } } else { fssize.folders = append(fssize.folders, File{path: path, sizeBytes: dirSize}) @@ -344,9 +344,9 @@ func (fssize *FSSize) AccumulateFilesAndFolders() error { fssize.files = append(fssize.files, File{path: path, sizeBytes: info.Size()}) fssize.SortFiles(&fssize.files) - if fssize.app != nil && fssize.currentTab == Files { + /*if fssize.app != nil && fssize.currentTab == Files { fssize.app.QueueUpdateDraw(func() {}) - } + }*/ return nil } diff --git a/main.go b/main.go index ef5475a..feceba3 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,7 @@ import ( "os" "path/filepath" "strings" + "time" "github.com/gdamore/tcell/v2" "github.com/rivo/tview" @@ -15,7 +16,7 @@ import ( ) const programName = "fssize" -const version = "v0.0.1" +const version = "v0.0.2" func printError(str string) { os.Stderr.WriteString("\x1b[0;31m" + programName + ": " + str + "\x1b[0m\n") @@ -153,6 +154,14 @@ This outputs the estimated kibibyte (KiB) size of all packages`) fssize.AccumulatePackages() go fssize.AccumulateFilesAndFolders() + fssize.accumulating = true // Just to make sure the below goroutine doesn't quit early + go func() { + for fssize.accumulating { + time.Sleep(250 * time.Millisecond) + app.QueueUpdateDraw(func() {}) + } + }() + if err := app.SetRoot(fssize, true).Run(); err != nil { log.Fatal(err) }