From 620ebc26af8d32037158635d5e4ce11015d4a830 Mon Sep 17 00:00:00 2001 From: intergrav Date: Thu, 2 Jul 2026 03:40:14 -0400 Subject: [PATCH] refactor: use humanize lib for formatsize might as well since we already have the library available --- cmd/restray/operations.go | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/cmd/restray/operations.go b/cmd/restray/operations.go index 6060dc8..7cbbeee 100644 --- a/cmd/restray/operations.go +++ b/cmd/restray/operations.go @@ -15,6 +15,7 @@ import ( "time" "fyne.io/systray" + "github.com/dustin/go-humanize" "github.com/gen2brain/beeep" ) @@ -98,19 +99,6 @@ func runRestic(key profileKey, prof Profile, mStatus prefixedMenuItem, args ...s return msg, err } -func formatSize(sz uint64) string { - switch { - case sz >= 1e9: - return fmt.Sprintf("%.1f GB", float64(sz)/1e9) - case sz >= 1e6: - return fmt.Sprintf("%.1f MB", float64(sz)/1e6) - case sz >= 1e3: - return fmt.Sprintf("%.0f KB", float64(sz)/1e3) - default: - return fmt.Sprintf("%d bytes", sz) - } -} - func doBackupOnce(key profileKey, mStatus prefixedMenuItem, prof Profile, args []string) (bool, int) { cmd := resticCmd(prof, args...) stdoutPipe, _ := cmd.StdoutPipe() @@ -145,7 +133,7 @@ func doBackupOnce(key profileKey, mStatus prefixedMenuItem, prof Profile, args [ switch { case msg.Total > 0: mStatus.SetTitle(fmt.Sprintf("%d%% completed, %s of %s", - int(msg.Percent*100), formatSize(msg.Bytes), formatSize(msg.Total))) + int(msg.Percent*100), humanize.Bytes(msg.Bytes), humanize.Bytes(msg.Total))) case msg.TotalFiles > 0: mStatus.SetTitle(fmt.Sprintf("Scanning: %d / %d files", msg.FilesDone, msg.TotalFiles)) -- 2.51.2