summaryrefslogtreecommitdiffstats
path: root/stdout
diff options
context:
space:
mode:
authorDaniel Milde <daniel@milde.cz>2024-05-21 13:38:06 +0200
committerDaniel Milde <daniel@milde.cz>2024-05-21 13:57:42 +0200
commit7ad59f4fa85fa42cb282d76770606dfdc61ba661 (patch)
tree4c9545be4bada4f3a211e9820e4d82b1f1f59ee2 /stdout
parent55b21a1e73885613907f975d871e040a171cf37d (diff)
feat: add option `--no-unicode` to disable unicode symbols
Diffstat (limited to 'stdout')
-rw-r--r--stdout/stdout.go17
-rw-r--r--stdout/stdout_test.go15
2 files changed, 28 insertions, 4 deletions
diff --git a/stdout/stdout.go b/stdout/stdout.go
index 669fc69..ced65fd 100644
--- a/stdout/stdout.go
+++ b/stdout/stdout.go
@@ -28,7 +28,11 @@ type UI struct {
noPrefix bool
}
-var progressRunes = []rune(`⠇⠏⠋⠙⠹⠸⠼⠴⠦⠧`)
+var (
+ progressRunes = []rune(`⠇⠏⠋⠙⠹⠸⠼⠴⠦⠧`)
+ progressRunesOld = []rune(`-\\|/`)
+ progressRunesCount = len(progressRunes)
+)
// CreateStdoutUI creates UI for stdout
func CreateStdoutUI(
@@ -68,6 +72,11 @@ func CreateStdoutUI(
return ui
}
+func (ui *UI) UseOldProgressRunes() {
+ progressRunes = progressRunesOld
+ progressRunesCount = len(progressRunes)
+}
+
// StartUILoop stub
func (ui *UI) StartUILoop() error {
return nil
@@ -321,7 +330,7 @@ func (ui *UI) showReadingProgress(doneChan chan struct{}) {
time.Sleep(100 * time.Millisecond)
i++
- i %= 10
+ i %= progressRunesCount
}
}
@@ -349,7 +358,7 @@ func (ui *UI) updateProgress(updateStatsDone <-chan struct{}) {
fmt.Fprint(ui.output, "Calculating disk usage...")
time.Sleep(100 * time.Millisecond)
i++
- i %= 10
+ i %= progressRunesCount
select {
case <-updateStatsDone:
@@ -370,7 +379,7 @@ func (ui *UI) updateProgress(updateStatsDone <-chan struct{}) {
time.Sleep(100 * time.Millisecond)
i++
- i %= 10
+ i %= progressRunesCount
}
}
diff --git a/stdout/stdout_test.go b/stdout/stdout_test.go
index 240ed13..cd76bd9 100644
--- a/stdout/stdout_test.go
+++ b/stdout/stdout_test.go
@@ -101,6 +101,21 @@ func TestAnalyzePathWithColors(t *testing.T) {
assert.Contains(t, output.String(), "subnested")
}
+func TestAnalyzePathWoUnicode(t *testing.T) {
+ fin := testdir.CreateTestDir()
+ defer fin()
+
+ buff := make([]byte, 10)
+ output := bytes.NewBuffer(buff)
+
+ ui := CreateStdoutUI(output, false, true, true, false, false, false, false, false)
+ ui.UseOldProgressRunes()
+ err := ui.AnalyzePath("test_dir/nested", nil)
+
+ assert.Nil(t, err)
+ assert.Contains(t, output.String(), "subnested")
+}
+
func TestItemRows(t *testing.T) {
output := bytes.NewBuffer(make([]byte, 10))