summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRamon Garcia-Perez <ramgarcia@outlook.com>2024-03-22 04:07:43 -0400
committerDaniel Milde <daniel@milde.cz>2024-03-22 18:29:16 +0100
commit58ad4d3816f8ebcd729587bf13fc4c0da635eb19 (patch)
tree643f8c7b78d89762e47d6e812e15011560ca118e
parent186a605d9315fe8386c3a46fbc19a9f782ed8e21 (diff)
feat: add --show-item-count (-C) option
-rw-r--r--cmd/gdu/app/app.go6
-rw-r--r--cmd/gdu/main.go1
-rw-r--r--tui/tui.go6
-rw-r--r--tui/tui_test.go12
4 files changed, 23 insertions, 2 deletions
diff --git a/cmd/gdu/app/app.go b/cmd/gdu/app/app.go
index c0ecd2b..ca8879e 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 2336fbb..885fd6d 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 ae2b2f6..4e03aa3 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 0a3dbcd..4237e18 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()