summaryrefslogtreecommitdiffstats
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
parent55b21a1e73885613907f975d871e040a171cf37d (diff)
feat: add option `--no-unicode` to disable unicode symbols
-rw-r--r--cmd/gdu/app/app.go9
-rw-r--r--cmd/gdu/app/app_test.go18
-rw-r--r--cmd/gdu/main.go1
-rw-r--r--stdout/stdout.go17
-rw-r--r--stdout/stdout_test.go15
5 files changed, 54 insertions, 6 deletions
diff --git a/cmd/gdu/app/app.go b/cmd/gdu/app/app.go
index 7f9612c..5860453 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 61e0255..55b428a 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 a842f10..e79e0dd 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 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))