Skip to content

Commit

Permalink
Make faster by only updating screen every 250ms
Browse files Browse the repository at this point in the history
  • Loading branch information
kivattt committed Sep 12, 2024
1 parent c8e8d00 commit 280b9ab
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
8 changes: 4 additions & 4 deletions fssize.go
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down Expand Up @@ -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
}

Expand Down
11 changes: 10 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"path/filepath"
"strings"
"time"

"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
Expand All @@ -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")
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 280b9ab

Please sign in to comment.