summaryrefslogtreecommitdiffstats
path: root/stdout
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 /stdout
parentf9a1ac3fbba069c10bdc7aa25abeb6488c731911 (diff)
formatting constants moved to common
Diffstat (limited to 'stdout')
-rw-r--r--stdout/stdout.go22
-rw-r--r--stdout/stdout_test.go15
2 files changed, 28 insertions, 9 deletions
diff --git a/stdout/stdout.go b/stdout/stdout.go
index 7da9f7b..0d246ad 100644
--- a/stdout/stdout.go
+++ b/stdout/stdout.go
@@ -215,15 +215,21 @@ func (ui *UI) updateProgress() {
}
func (ui *UI) formatSize(size int64) string {
+ fsize := float64(size)
+
switch {
- case size > 1e12:
- return ui.orange.Sprintf("%.1f", float64(size)/math.Pow(2, 40)) + " TiB"
- case size > 1e9:
- return ui.orange.Sprintf("%.1f", float64(size)/math.Pow(2, 30)) + " GiB"
- case size > 1e6:
- return ui.orange.Sprintf("%.1f", float64(size)/math.Pow(2, 20)) + " MiB"
- case size > 1e3:
- return ui.orange.Sprintf("%.1f", float64(size)/math.Pow(2, 10)) + " KiB"
+ case fsize >= common.EB:
+ return ui.orange.Sprintf("%.1f", fsize/common.EB) + " EiB"
+ case fsize >= common.PB:
+ return ui.orange.Sprintf("%.1f", fsize/common.PB) + " PiB"
+ case fsize >= common.TB:
+ return ui.orange.Sprintf("%.1f", fsize/common.TB) + " TiB"
+ case fsize >= common.GB:
+ return ui.orange.Sprintf("%.1f", fsize/common.GB) + " GiB"
+ case fsize >= common.MB:
+ return ui.orange.Sprintf("%.1f", fsize/common.MB) + " MiB"
+ case fsize >= common.KB:
+ return ui.orange.Sprintf("%.1f", fsize/common.KB) + " KiB"
default:
return ui.orange.Sprintf("%d", size) + " B"
}
diff --git a/stdout/stdout_test.go b/stdout/stdout_test.go
index 9ad6c8d..1022285 100644
--- a/stdout/stdout_test.go
+++ b/stdout/stdout_test.go
@@ -86,7 +86,6 @@ func TestItemRows(t *testing.T) {
err := ui.AnalyzePath("test_dir", nil)
assert.Nil(t, err)
- assert.Contains(t, output.String(), "TiB")
assert.Contains(t, output.String(), "GiB")
assert.Contains(t, output.String(), "MiB")
assert.Contains(t, output.String(), "KiB")
@@ -133,6 +132,20 @@ func TestMaxInt(t *testing.T) {
assert.Equal(t, 4, maxInt(4, 2))
}
+func TestFormatSize(t *testing.T) {
+ output := bytes.NewBuffer(make([]byte, 10))
+
+ ui := CreateStdoutUI(output, true, true, true)
+
+ assert.Contains(t, ui.formatSize(1), "B")
+ assert.Contains(t, ui.formatSize(1<<10+1), "KiB")
+ assert.Contains(t, ui.formatSize(1<<20+1), "MiB")
+ assert.Contains(t, ui.formatSize(1<<30+1), "GiB")
+ assert.Contains(t, ui.formatSize(1<<40+1), "TiB")
+ assert.Contains(t, ui.formatSize(1<<50+1), "PiB")
+ assert.Contains(t, ui.formatSize(1<<60+1), "EiB")
+}
+
// func printBuffer(buff *bytes.Buffer) {
// for i, x := range buff.String() {
// println(i, string(x))