Skip to content

Commit

Permalink
feat: configuration option for setting maximum length of the path for…
Browse files Browse the repository at this point in the history
… current item in the progress modal
  • Loading branch information
dundee committed Sep 18, 2022
1 parent 3a5d27a commit 0c829d2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
13 changes: 12 additions & 1 deletion cmd/gdu/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,13 @@ type Flags struct {

// Style define style config
type Style struct {
SelectedRow ColorStyle `yaml:"selected-row"`
SelectedRow ColorStyle `yaml:"selected-row"`
ProgressModal ProgressModalOpts `yaml:"progress-modal"`
}

// ProgressModalOpts defines options for progress modal
type ProgressModalOpts struct {
CurrentItemNameMaxLen int `yaml:"current-item-path-max-len"`
}

// ColorStyle defines styling of some item
Expand Down Expand Up @@ -218,6 +224,11 @@ func (a *App) createUI() (UI, error) {
ui.SetSelectedBackgroundColor(tcell.GetColor(a.Flags.Style.SelectedRow.BackgroundColor))
})
}
if a.Flags.Style.ProgressModal.CurrentItemNameMaxLen > 0 {
opts = append(opts, func(ui *tui.UI) {
ui.SetCurrentItemNameMaxLen(a.Flags.Style.ProgressModal.CurrentItemNameMaxLen)
})
}

ui = tui.CreateUI(
a.TermApp,
Expand Down
3 changes: 3 additions & 0 deletions cmd/gdu/app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ func TestAnalyzePathWithStyle(t *testing.T) {
TextColor: "black",
BackgroundColor: "red",
},
ProgressModal: ProgressModalOpts{
CurrentItemNameMaxLen: 10,
},
},
},
[]string{"test_dir"},
Expand Down
2 changes: 1 addition & 1 deletion tui/progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (ui *UI) updateProgress() {
color +
delta.String() +
"[white:black:-]\nCurrent item: [white:black:b]" +
path.ShortenPath(currentItem, 70))
path.ShortenPath(currentItem, ui.currentItemNameMaxLen))
})
}(progress.ItemCount, progress.TotalSize, progress.CurrentItemName)

Expand Down
8 changes: 8 additions & 0 deletions tui/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ type UI struct {
linkedItems fs.HardLinkedItems
selectedTextColor tcell.Color
selectedBackgroundColor tcell.Color
currentItemNameMaxLen int
}

// Option is optional function customizing the bahaviour of UI
Expand Down Expand Up @@ -112,6 +113,7 @@ func CreateUI(
linkedItems: make(fs.HardLinkedItems, 10),
selectedTextColor: tview.Styles.TitleColor,
selectedBackgroundColor: tview.Styles.MoreContrastBackgroundColor,
currentItemNameMaxLen: 70,
}
for _, o := range opts {
o(ui)
Expand Down Expand Up @@ -192,6 +194,12 @@ func (ui *UI) SetSelectedBackgroundColor(color tcell.Color) {
ui.selectedBackgroundColor = color
}

// SetCurrentItemNameMaxLen sets the maximum length of the path of the currently processed item
// to be shown in the progress modal
func (ui *UI) SetCurrentItemNameMaxLen(len int) {
ui.currentItemNameMaxLen = len
}

// StartUILoop starts tview application
func (ui *UI) StartUILoop() error {
return ui.app.Run()
Expand Down

0 comments on commit 0c829d2

Please sign in to comment.