summaryrefslogtreecommitdiffstats
path: root/tui/format.go
diff options
context:
space:
mode:
authorDaniel Milde <daniel@milde.cz>2021-07-10 11:09:55 +0200
committerDaniel Milde <daniel@milde.cz>2021-07-10 23:51:47 +0200
commit1ea6de51490c00eccfffcf261b822e54eaa0de74 (patch)
tree32f9b5749c58b2963f0151940aa5a994a940eb2e /tui/format.go
parentf9a1ac3fbba069c10bdc7aa25abeb6488c731911 (diff)
formatting constants moved to common
Diffstat (limited to 'tui/format.go')
-rw-r--r--tui/format.go55
1 files changed, 19 insertions, 36 deletions
diff --git a/tui/format.go b/tui/format.go
index ec9e0e5..a18802d 100644
--- a/tui/format.go
+++ b/tui/format.go
@@ -3,27 +3,10 @@ package tui
import (
"fmt"
+ "github.com/dundee/gdu/v5/internal/common"
"github.com/dundee/gdu/v5/pkg/analyze"
)
-// file size constants
-const (
- _ = iota
- KB float64 = 1 << (10 * iota)
- MB
- GB
- TB
- PB
- EB
-)
-
-// file count constants
-const (
- K int = 1e3
- M int = 1e6
- G int = 1e9
-)
-
func (ui *UI) formatFileRow(item analyze.Item) string {
var part int
@@ -88,18 +71,18 @@ func (ui *UI) formatSize(size int64, reverseColor bool, transparentBg bool) stri
fsize := float64(size)
switch {
- case fsize >= EB:
- return fmt.Sprintf("%.1f%s EiB", fsize/EB, color)
- case fsize >= PB:
- return fmt.Sprintf("%.1f%s PiB", fsize/PB, color)
- case fsize >= TB:
- return fmt.Sprintf("%.1f%s TiB", fsize/TB, color)
- case fsize >= GB:
- return fmt.Sprintf("%.1f%s GiB", fsize/GB, color)
- case fsize >= MB:
- return fmt.Sprintf("%.1f%s MiB", fsize/MB, color)
- case fsize >= KB:
- return fmt.Sprintf("%.1f%s KiB", fsize/KB, color)
+ case fsize >= common.EB:
+ return fmt.Sprintf("%.1f%s EiB", fsize/common.EB, color)
+ case fsize >= common.PB:
+ return fmt.Sprintf("%.1f%s PiB", fsize/common.PB, color)
+ case fsize >= common.TB:
+ return fmt.Sprintf("%.1f%s TiB", fsize/common.TB, color)
+ case fsize >= common.GB:
+ return fmt.Sprintf("%.1f%s GiB", fsize/common.GB, color)
+ case fsize >= common.MB:
+ return fmt.Sprintf("%.1f%s MiB", fsize/common.MB, color)
+ case fsize >= common.KB:
+ return fmt.Sprintf("%.1f%s KiB", fsize/common.KB, color)
default:
return fmt.Sprintf("%d%s B", size, color)
}
@@ -110,12 +93,12 @@ func (ui *UI) formatCount(count int) string {
color := "[-::]"
switch {
- case count >= G:
- row += fmt.Sprintf("%.1f%sG", float64(count)/float64(G), color)
- case count >= M:
- row += fmt.Sprintf("%.1f%sM", float64(count)/float64(M), color)
- case count >= K:
- row += fmt.Sprintf("%.1f%sk", float64(count)/float64(K), color)
+ case count >= common.G:
+ row += fmt.Sprintf("%.1f%sG", float64(count)/float64(common.G), color)
+ case count >= common.M:
+ row += fmt.Sprintf("%.1f%sM", float64(count)/float64(common.M), color)
+ case count >= common.K:
+ row += fmt.Sprintf("%.1f%sk", float64(count)/float64(common.K), color)
default:
row += fmt.Sprintf("%d%s", count, color)
}