Skip to content

Commit

Permalink
feat: add --show-item-count (-C) option
Browse files Browse the repository at this point in the history
  • Loading branch information
ramgp authored and dundee committed Mar 22, 2024
1 parent 186a605 commit 58ad4d3
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
6 changes: 6 additions & 0 deletions cmd/gdu/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions cmd/gdu/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
6 changes: 4 additions & 2 deletions tui/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down
12 changes: 12 additions & 0 deletions tui/tui_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 58ad4d3

Please sign in to comment.