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))