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

Add configurable option to show number of items column #331

Closed
erhhung opened this issue Mar 8, 2024 · 3 comments
Closed

Add configurable option to show number of items column #331

erhhung opened this issue Mar 8, 2024 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@erhhung
Copy link

erhhung commented Mar 8, 2024

The option to toggle the display of the number of items in a directory is already available in the TUI by pressing c, but the items column is always hidden by default. There's no CLI option to show that column in the TUI and in non-interactive and export output modes, and also no way to set that in the gdu.yaml config file.

Describe the solution you'd like

Allow a CLI option, such as --show-counts/-C, and corresponding config file setting show-counts: true to enable showing the number of items column by default (in JSON output, include explicit items property instead of merely checking array length).

An even better enhancement would be separating "number of items" values into distinct "number of files" and "number of subdirectories" counts (in JSON output, include files and subdirs properties instead of items for directory objects).

@dundee dundee added the enhancement New feature or request label Mar 11, 2024
@ramgp
Copy link
Contributor

ramgp commented Mar 19, 2024

Hi, I took a wack at this (I use the tool and I have programming skills, so why not)

First I decided to do it the long route and the ripple effect of changing the main UI factory (CreateUI) was too much. I got to admit I barely know the project, but that was a fun exercise having to change a bunch of places including a lot of test that use the default factory to create the UI object they work with

The second approach was much more simple and involved using the opts and a setter

I would like to add some unit tests, what would be some test cases to include with it. Please let me know if this approach is appropriate, these are the changes I did (I kept the names consistent with the existing code base):

tui/tui.go

// line: 204
func (ui *UI) SetShowItemCount() {
  ui.showItemCount = true
}

app/app.go

// line: 58
ShowItemCount      bool     `yaml:"show-item-count"`

// line: 271
if a.Flags.ShowItemCount {
  opts = append(opts, func(ui *tui.UI) {
    ui.SetShowItemCount()
  })
}

main.go

// line: 71
flags.BoolVarP(&af.ShowItemCount, "show-item-count", "C", false, "Show number of items in directory")

@dundee
Copy link
Owner

dundee commented Mar 19, 2024

Yes, I think the setter is the correct approach here.

@dundee
Copy link
Owner

dundee commented Mar 22, 2024

Resolved in #332.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants