From 58ad4d3816f8ebcd729587bf13fc4c0da635eb19 Mon Sep 17 00:00:00 2001 From: Ramon Garcia-Perez Date: Fri, 22 Mar 2024 04:07:43 -0400 Subject: [PATCH] feat: add --show-item-count (-C) option --- cmd/gdu/app/app.go | 6 ++++++ cmd/gdu/main.go | 1 + tui/tui.go | 6 ++++-- tui/tui_test.go | 12 ++++++++++++ 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/cmd/gdu/app/app.go b/cmd/gdu/app/app.go index c0ecd2bff..ca8879ea7 100644 --- a/cmd/gdu/app/app.go +++ b/cmd/gdu/app/app.go @@ -56,6 +56,7 @@ type Flags struct { ShowApparentSize bool `yaml:"show-apparent-size"` ShowRelativeSize bool `yaml:"show-relative-size"` ShowVersion bool `yaml:"-"` + ShowItemCount bool `yaml:"show-item-count"` NoColor bool `yaml:"no-color"` NoMouse bool `yaml:"no-mouse"` NonInteractive bool `yaml:"non-interactive"` @@ -268,6 +269,11 @@ func (a *App) createUI() (UI, error) { ui.SetChangeCwdFn(os.Chdir) }) } + if a.Flags.ShowItemCount { + opts = append(opts, func(ui *tui.UI) { + ui.SetShowItemCount() + }) + } ui = tui.CreateUI( a.TermApp, diff --git a/cmd/gdu/main.go b/cmd/gdu/main.go index 2336fbb84..885fd6d57 100644 --- a/cmd/gdu/main.go +++ b/cmd/gdu/main.go @@ -66,6 +66,7 @@ func init() { flags.BoolVarP(&af.ShowApparentSize, "show-apparent-size", "a", false, "Show apparent size") flags.BoolVarP(&af.ShowRelativeSize, "show-relative-size", "B", false, "Show relative size") flags.BoolVarP(&af.NoColor, "no-color", "c", false, "Do not use colorized output") + flags.BoolVarP(&af.ShowItemCount, "show-item-count", "C", false, "Show number 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.Summarize, "summarize", "s", false, "Show only a total in non-interactive mode") diff --git a/tui/tui.go b/tui/tui.go index ae2b2f663..4e03aa343 100644 --- a/tui/tui.go +++ b/tui/tui.go @@ -137,7 +137,6 @@ func CreateUI( ui.table.SetSelectedFunc(ui.fileItemSelected) if ui.UseColors { - ui.table.SetSelectedStyle(tcell.Style{}. Foreground(ui.selectedTextColor). Background(ui.selectedBackgroundColor).Bold(true)) @@ -202,6 +201,10 @@ func (ui *UI) StartUILoop() error { return ui.app.Run() } +func (ui *UI) SetShowItemCount() { + ui.showItemCount = true +} + func (ui *UI) resetSorting() { ui.sortBy = ui.defaultSortBy ui.sortOrder = ui.defaultSortOrder @@ -262,7 +265,6 @@ func (ui *UI) deviceItemSelected(row, column int) { paths := device.GetNestedMountpointsPaths(selectedDevice.MountPoint, ui.devices) ui.IgnoreDirPathPatterns, err = common.CreateIgnorePattern(paths) - if err != nil { log.Printf("Creating path patterns for other devices failed: %s", paths) } diff --git a/tui/tui_test.go b/tui/tui_test.go index 0a3dbcda6..4237e184a 100644 --- a/tui/tui_test.go +++ b/tui/tui_test.go @@ -452,6 +452,18 @@ func TestUseOldSizeBar(t *testing.T) { assert.Equal(t, ui.useOldSizeBar, true) } +func TestSetShowItemCount(t *testing.T) { + simScreen := testapp.CreateSimScreen() + defer simScreen.Fini() + + app := testapp.CreateMockedApp(true) + ui := CreateUI(app, simScreen, &bytes.Buffer{}, false, true, false, false, false) + + ui.SetShowItemCount() + + assert.Equal(t, ui.showItemCount, true) +} + // nolint: deadcode,unused // Why: for debugging func printScreen(simScreen tcell.SimulationScreen) { b, _, _ := simScreen.GetContents()