summaryrefslogtreecommitdiffstats
path: root/stdout
diff options
context:
space:
mode:
authorDaniel Milde <daniel@milde.cz>2022-08-03 00:08:10 +0200
committerDaniel Milde <daniel@milde.cz>2022-08-03 00:08:10 +0200
commit5d7cd6ae8d255a01fbb1afb032ad1c1fe338c3b4 (patch)
tree8eb5893ee30053836ea32e03fe23d2f511e10f2c /stdout
parent386ada6004afb9f54825285678ce5397ccc2583d (diff)
feat: show sizes as raw numbers without prefixesv5.15.0
closes #147
Diffstat (limited to 'stdout')
-rw-r--r--stdout/stdout.go6
-rw-r--r--stdout/stdout_linux_test.go2
-rw-r--r--stdout/stdout_test.go44
3 files changed, 36 insertions, 16 deletions
diff --git a/stdout/stdout.go b/stdout/stdout.go
index 60e5d85..f20e311 100644
--- a/stdout/stdout.go
+++ b/stdout/stdout.go
@@ -25,6 +25,7 @@ type UI struct {
orange *color.Color
blue *color.Color
summarize bool
+ noPrefix bool
}
var progressRunes = []rune(`⠇⠏⠋⠙⠹⠸⠼⠴⠦⠧`)
@@ -39,6 +40,7 @@ func CreateStdoutUI(
summarize bool,
constGC bool,
useSIPrefix bool,
+ noPrefix bool,
) *UI {
ui := &UI{
UI: &common.UI{
@@ -52,6 +54,7 @@ func CreateStdoutUI(
},
output: output,
summarize: summarize,
+ noPrefix: noPrefix,
}
ui.red = color.New(color.FgRed).Add(color.Bold)
@@ -336,6 +339,9 @@ func (ui *UI) updateProgress() {
}
func (ui *UI) formatSize(size int64) string {
+ if ui.noPrefix {
+ return ui.orange.Sprintf("%d", size)
+ }
if ui.UseSIPrefix {
return ui.formatWithDecPrefix(size)
}
diff --git a/stdout/stdout_linux_test.go b/stdout/stdout_linux_test.go
index b062e6c..4a47dae 100644
--- a/stdout/stdout_linux_test.go
+++ b/stdout/stdout_linux_test.go
@@ -21,7 +21,7 @@ func TestShowDevicesWithErr(t *testing.T) {
output := bytes.NewBuffer(make([]byte, 10))
getter := device.LinuxDevicesInfoGetter{MountsPath: "/xyzxyz"}
- ui := CreateStdoutUI(output, false, true, false, false, false, false, false)
+ ui := CreateStdoutUI(output, false, true, false, false, false, false, false, false)
err := ui.ListDevices(getter)
assert.Contains(t, err.Error(), "no such file")
diff --git a/stdout/stdout_test.go b/stdout/stdout_test.go
index 425765b..2146367 100644
--- a/stdout/stdout_test.go
+++ b/stdout/stdout_test.go
@@ -25,7 +25,7 @@ func TestAnalyzePath(t *testing.T) {
buff := make([]byte, 10)
output := bytes.NewBuffer(buff)
- ui := CreateStdoutUI(output, false, false, false, false, false, true, false)
+ ui := CreateStdoutUI(output, false, false, false, false, false, true, false, false)
ui.SetIgnoreDirPaths([]string{"/xxx"})
err := ui.AnalyzePath("test_dir", nil)
assert.Nil(t, err)
@@ -42,7 +42,7 @@ func TestShowSummary(t *testing.T) {
buff := make([]byte, 10)
output := bytes.NewBuffer(buff)
- ui := CreateStdoutUI(output, true, false, true, false, true, false, false)
+ ui := CreateStdoutUI(output, true, false, true, false, true, false, false, false)
ui.SetIgnoreDirPaths([]string{"/xxx"})
err := ui.AnalyzePath("test_dir", nil)
assert.Nil(t, err)
@@ -59,7 +59,7 @@ func TestShowSummaryBw(t *testing.T) {
buff := make([]byte, 10)
output := bytes.NewBuffer(buff)
- ui := CreateStdoutUI(output, false, false, false, false, true, false, false)
+ ui := CreateStdoutUI(output, false, false, false, false, true, false, false, false)
ui.SetIgnoreDirPaths([]string{"/xxx"})
err := ui.AnalyzePath("test_dir", nil)
assert.Nil(t, err)
@@ -76,7 +76,7 @@ func TestAnalyzeSubdir(t *testing.T) {
buff := make([]byte, 10)
output := bytes.NewBuffer(buff)
- ui := CreateStdoutUI(output, false, false, false, false, false, false, false)
+ ui := CreateStdoutUI(output, false, false, false, false, false, false, false, false)
ui.SetIgnoreDirPaths([]string{"/xxx"})
err := ui.AnalyzePath("test_dir/nested", nil)
assert.Nil(t, err)
@@ -93,7 +93,7 @@ func TestAnalyzePathWithColors(t *testing.T) {
buff := make([]byte, 10)
output := bytes.NewBuffer(buff)
- ui := CreateStdoutUI(output, true, false, true, false, false, false, false)
+ ui := CreateStdoutUI(output, true, false, true, false, false, false, false, false)
ui.SetIgnoreDirPaths([]string{"/xxx"})
err := ui.AnalyzePath("test_dir/nested", nil)
@@ -104,7 +104,7 @@ func TestAnalyzePathWithColors(t *testing.T) {
func TestItemRows(t *testing.T) {
output := bytes.NewBuffer(make([]byte, 10))
- ui := CreateStdoutUI(output, false, true, false, false, false, false, false)
+ ui := CreateStdoutUI(output, false, true, false, false, false, false, false, false)
ui.Analyzer = &testanalyze.MockedAnalyzer{}
err := ui.AnalyzePath("test_dir", nil)
@@ -118,7 +118,7 @@ func TestAnalyzePathWithProgress(t *testing.T) {
output := bytes.NewBuffer(make([]byte, 10))
- ui := CreateStdoutUI(output, false, true, true, false, false, false, false)
+ ui := CreateStdoutUI(output, false, true, true, false, false, false, false, false)
ui.SetIgnoreDirPaths([]string{"/xxx"})
err := ui.AnalyzePath("test_dir", nil)
@@ -129,7 +129,7 @@ func TestAnalyzePathWithProgress(t *testing.T) {
func TestShowDevices(t *testing.T) {
output := bytes.NewBuffer(make([]byte, 10))
- ui := CreateStdoutUI(output, false, true, false, false, false, false, false)
+ ui := CreateStdoutUI(output, false, true, false, false, false, false, false, false)
err := ui.ListDevices(getDevicesInfoMock())
assert.Nil(t, err)
@@ -140,7 +140,7 @@ func TestShowDevices(t *testing.T) {
func TestShowDevicesWithColor(t *testing.T) {
output := bytes.NewBuffer(make([]byte, 10))
- ui := CreateStdoutUI(output, true, true, true, false, false, false, false)
+ ui := CreateStdoutUI(output, true, true, true, false, false, false, false, false)
err := ui.ListDevices(getDevicesInfoMock())
assert.Nil(t, err)
@@ -154,7 +154,7 @@ func TestReadAnalysisWithColor(t *testing.T) {
output := bytes.NewBuffer(make([]byte, 10))
- ui := CreateStdoutUI(output, true, true, true, false, false, false, false)
+ ui := CreateStdoutUI(output, true, true, true, false, false, false, false, false)
err = ui.ReadAnalysis(input)
assert.Nil(t, err)
@@ -167,7 +167,7 @@ func TestReadAnalysisBw(t *testing.T) {
output := bytes.NewBuffer(make([]byte, 10))
- ui := CreateStdoutUI(output, false, false, false, false, false, false, false)
+ ui := CreateStdoutUI(output, false, false, false, false, false, false, false, false)
err = ui.ReadAnalysis(input)
assert.Nil(t, err)
@@ -180,7 +180,7 @@ func TestReadAnalysisWithWrongFile(t *testing.T) {
output := bytes.NewBuffer(make([]byte, 10))
- ui := CreateStdoutUI(output, true, true, true, false, false, false, false)
+ ui := CreateStdoutUI(output, true, true, true, false, false, false, false, false)
err = ui.ReadAnalysis(input)
assert.NotNil(t, err)
@@ -192,7 +192,7 @@ func TestReadAnalysisWithSummarize(t *testing.T) {
output := bytes.NewBuffer(make([]byte, 10))
- ui := CreateStdoutUI(output, false, false, false, false, true, false, false)
+ ui := CreateStdoutUI(output, false, false, false, false, true, false, false, false)
err = ui.ReadAnalysis(input)
assert.Nil(t, err)
@@ -207,7 +207,7 @@ func TestMaxInt(t *testing.T) {
func TestFormatSize(t *testing.T) {
output := bytes.NewBuffer(make([]byte, 10))
- ui := CreateStdoutUI(output, true, true, true, false, false, false, false)
+ ui := CreateStdoutUI(output, true, true, true, false, false, false, false, false)
assert.Contains(t, ui.formatSize(1), "B")
assert.Contains(t, ui.formatSize(1<<10+1), "KiB")
@@ -221,7 +221,7 @@ func TestFormatSize(t *testing.T) {
func TestFormatSizeDec(t *testing.T) {
output := bytes.NewBuffer(make([]byte, 10))
- ui := CreateStdoutUI(output, true, true, true, false, false, false, true)
+ ui := CreateStdoutUI(output, true, true, true, false, false, false, true, false)
assert.Contains(t, ui.formatSize(1), "B")
assert.Contains(t, ui.formatSize(1<<10+1), "kB")
@@ -232,6 +232,20 @@ func TestFormatSizeDec(t *testing.T) {
assert.Contains(t, ui.formatSize(1<<60+1), "EB")
}
+func TestFormatSizeRaw(t *testing.T) {
+ output := bytes.NewBuffer(make([]byte, 10))
+
+ ui := CreateStdoutUI(output, true, true, true, false, false, false, true, true)
+
+ assert.Equal(t, ui.formatSize(1), "1")
+ assert.Equal(t, ui.formatSize(1<<10+1), "1025")
+ assert.Equal(t, ui.formatSize(1<<20+1), "1048577")
+ assert.Equal(t, ui.formatSize(1<<30+1), "1073741825")
+ assert.Equal(t, ui.formatSize(1<<40+1), "1099511627777")
+ assert.Equal(t, ui.formatSize(1<<50+1), "1125899906842625")
+ assert.Equal(t, ui.formatSize(1<<60+1), "1152921504606846977")
+}
+
// func printBuffer(buff *bytes.Buffer) {
// for i, x := range buff.String() {
// println(i, string(x))