diff --git a/cmd/gdu/app/app.go b/cmd/gdu/app/app.go index 7f9612cf1..5860453f1 100644 --- a/cmd/gdu/app/app.go +++ b/cmd/gdu/app/app.go @@ -61,6 +61,7 @@ type Flags struct { NoMouse bool `yaml:"no-mouse"` NonInteractive bool `yaml:"non-interactive"` NoProgress bool `yaml:"no-progress"` + NoUnicode bool `yaml:"no-unicode"` NoCross bool `yaml:"no-cross"` NoHidden bool `yaml:"no-hidden"` NoDelete bool `yaml:"no-delete"` @@ -231,7 +232,7 @@ func (a *App) createUI() (UI, error) { a.Flags.UseSIPrefix, ) case a.Flags.NonInteractive || !a.Istty: - ui = stdout.CreateStdoutUI( + stdoutUI := stdout.CreateStdoutUI( a.Writer, !a.Flags.NoColor && a.Istty, !a.Flags.NoProgress && a.Istty, @@ -242,6 +243,10 @@ func (a *App) createUI() (UI, error) { a.Flags.UseSIPrefix, a.Flags.NoPrefix, ) + if a.Flags.NoUnicode { + stdoutUI.UseOldProgressRunes() + } + ui = stdoutUI default: var opts []tui.Option @@ -260,7 +265,7 @@ func (a *App) createUI() (UI, error) { ui.SetCurrentItemNameMaxLen(a.Flags.Style.ProgressModal.CurrentItemNameMaxLen) }) } - if a.Flags.Style.UseOldSizeBar { + if a.Flags.Style.UseOldSizeBar || a.Flags.NoUnicode { opts = append(opts, func(ui *tui.UI) { ui.UseOldSizeBar() }) diff --git a/cmd/gdu/app/app_test.go b/cmd/gdu/app/app_test.go index 61e0255f6..55b428ac1 100644 --- a/cmd/gdu/app/app_test.go +++ b/cmd/gdu/app/app_test.go @@ -287,6 +287,24 @@ func TestAnalyzePathWithStyle(t *testing.T) { assert.Nil(t, err) } +func TestAnalyzePathNoUnicode(t *testing.T) { + fin := testdir.CreateTestDir() + defer fin() + + out, err := runApp( + &Flags{ + LogFile: "/dev/null", + NoUnicode: true, + }, + []string{"test_dir"}, + false, + testdev.DevicesInfoGetterMock{}, + ) + + assert.Contains(t, out, "nested") + assert.Nil(t, err) +} + func TestAnalyzePathWithExport(t *testing.T) { fin := testdir.CreateTestDir() defer fin() diff --git a/cmd/gdu/main.go b/cmd/gdu/main.go index a842f1021..e79e0dda1 100644 --- a/cmd/gdu/main.go +++ b/cmd/gdu/main.go @@ -72,6 +72,7 @@ func init() { flags.BoolVarP(&af.ShowMTime, "show-mtime", "M", false, "Show latest mtime of items in directory") flags.BoolVarP(&af.NonInteractive, "non-interactive", "n", false, "Do not run in interactive mode") flags.BoolVarP(&af.NoProgress, "no-progress", "p", false, "Do not show progress in non-interactive mode") + flags.BoolVarP(&af.NoUnicode, "no-unicode", "u", false, "Do not use Unicode symbols (for size bar)") flags.BoolVarP(&af.Summarize, "summarize", "s", false, "Show only a total in non-interactive mode") flags.BoolVar(&af.UseSIPrefix, "si", false, "Show sizes with decimal SI prefixes (kB, MB, GB) instead of binary prefixes (KiB, MiB, GiB)") flags.BoolVar(&af.NoPrefix, "no-prefix", false, "Show sizes as raw numbers without any prefixes (SI or binary) in non-interactive mode") diff --git a/stdout/stdout.go b/stdout/stdout.go index 669fc69d4..ced65fd53 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 240ed1326..cd76bd92f 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))