Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add --show-item-count (-C) option, resolves #331 #332

Merged
merged 1 commit into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 @@
ui.SetChangeCwdFn(os.Chdir)
})
}
if a.Flags.ShowItemCount {
opts = append(opts, func(ui *tui.UI) {
ui.SetShowItemCount()
})

Check warning on line 275 in cmd/gdu/app/app.go

View check run for this annotation

Codecov / codecov/patch

cmd/gdu/app/app.go#L273-L275

Added lines #L273 - L275 were not covered by tests
}

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
Loading