From b20c46242321dc00c22ba0dbca0d72e53e192fa3 Mon Sep 17 00:00:00 2001 From: Daniel Milde Date: Sat, 28 Dec 2024 21:40:49 +0100 Subject: [PATCH 01/10] ci: bump golang version to 1.23.3 --- .tool-versions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.tool-versions b/.tool-versions index 3960504e7..e0217baa9 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1 +1 @@ -golang 1.22.2 +golang 1.23.3 From 1322bccf391b7a895f8e1b5955ccaf90d10c82bd Mon Sep 17 00:00:00 2001 From: Daniel Milde Date: Sat, 28 Dec 2024 21:41:34 +0100 Subject: [PATCH 02/10] feat: configurable style for footer --- cmd/gdu/app/app.go | 23 +++++++++++++++++++++++ cmd/gdu/main.go | 10 ++++++++++ tui/format.go | 6 +++++- tui/show.go | 13 +++++++++++-- tui/tui.go | 22 ++++++++++++++++++++-- 5 files changed, 69 insertions(+), 5 deletions(-) diff --git a/cmd/gdu/app/app.go b/cmd/gdu/app/app.go index 1a27d30a4..d1db635a4 100644 --- a/cmd/gdu/app/app.go +++ b/cmd/gdu/app/app.go @@ -88,6 +88,7 @@ type Style struct { SelectedRow ColorStyle `yaml:"selected-row"` ProgressModal ProgressModalOpts `yaml:"progress-modal"` UseOldSizeBar bool `yaml:"use-old-size-bar"` + Footer FooterColorStyle `yaml:"footer"` } // ProgressModalOpts defines options for progress modal @@ -101,6 +102,13 @@ type ColorStyle struct { BackgroundColor string `yaml:"background-color"` } +// ColorStyle defines styling of some item +type FooterColorStyle struct { + TextColor string `yaml:"text-color"` + BackgroundColor string `yaml:"background-color"` + NumberColor string `yaml:"number-color"` +} + // Sorting defines default sorting of items type Sorting struct { By string `yaml:"by"` @@ -262,6 +270,21 @@ func (a *App) createUI() (UI, error) { ui.SetSelectedBackgroundColor(tcell.GetColor(a.Flags.Style.SelectedRow.BackgroundColor)) }) } + if a.Flags.Style.Footer.TextColor != "" { + opts = append(opts, func(ui *tui.UI) { + ui.SetFooterTextColor(a.Flags.Style.Footer.TextColor) + }) + } + if a.Flags.Style.Footer.BackgroundColor != "" { + opts = append(opts, func(ui *tui.UI) { + ui.SetFooterBackgroundColor(a.Flags.Style.Footer.BackgroundColor) + }) + } + if a.Flags.Style.Footer.NumberColor != "" { + opts = append(opts, func(ui *tui.UI) { + ui.SetFooterNumberColor(a.Flags.Style.Footer.NumberColor) + }) + } if a.Flags.Style.ProgressModal.CurrentItemNameMaxLen > 0 { opts = append(opts, func(ui *tui.UI) { ui.SetCurrentItemNameMaxLen(a.Flags.Style.ProgressModal.CurrentItemNameMaxLen) diff --git a/cmd/gdu/main.go b/cmd/gdu/main.go index b256f7b29..2c5275ff1 100644 --- a/cmd/gdu/main.go +++ b/cmd/gdu/main.go @@ -93,6 +93,16 @@ func initConfig() { } configErr = yaml.Unmarshal(data, &af) + + if af.Style.Footer.BackgroundColor == "" { + af.Style.Footer.BackgroundColor = "#2479D0" + } + if af.Style.Footer.TextColor == "" { + af.Style.Footer.TextColor = "#000000" + } + if af.Style.Footer.NumberColor == "" { + af.Style.Footer.NumberColor = "#FFFFFF" + } } func setConfigFilePath() { diff --git a/tui/format.go b/tui/format.go index 360138ad6..3cc46d80a 100644 --- a/tui/format.go +++ b/tui/format.go @@ -100,7 +100,11 @@ func (ui *UI) formatSize(size int64, reverseColor, transparentBg bool) string { var color string if reverseColor { if ui.UseColors { - color = blackOnBlue + color = fmt.Sprintf( + "[%s:%s:-]", + ui.footerTextColor, + ui.footerBackgroundColor, + ) } else { color = blackOnWhite } diff --git a/tui/show.go b/tui/show.go index f8b1026e3..8a3124053 100644 --- a/tui/show.go +++ b/tui/show.go @@ -1,6 +1,7 @@ package tui import ( + "fmt" "strconv" "strings" @@ -148,8 +149,16 @@ func (ui *UI) showDir() { var footerNumberColor, footerTextColor string if ui.UseColors { - footerNumberColor = "[#ffffff:#2479d0:b]" - footerTextColor = blackOnBlue + footerNumberColor = fmt.Sprintf( + "[%s:%s:b]", + ui.footerNumberColor, + ui.footerBackgroundColor, + ) + footerTextColor = fmt.Sprintf( + "[%s:%s:-]", + ui.footerTextColor, + ui.footerBackgroundColor, + ) } else { footerNumberColor = "[black:white:b]" footerTextColor = blackOnWhite diff --git a/tui/tui.go b/tui/tui.go index 70c11e8b8..1c2cbb139 100644 --- a/tui/tui.go +++ b/tui/tui.go @@ -60,6 +60,9 @@ type UI struct { linkedItems fs.HardLinkedItems selectedTextColor tcell.Color selectedBackgroundColor tcell.Color + footerTextColor string + footerBackgroundColor string + footerNumberColor string currentItemNameMaxLen int useOldSizeBar bool defaultSortBy string @@ -173,8 +176,8 @@ func CreateUI( } ui.footerLabel = tview.NewTextView().SetDynamicColors(true) - ui.footerLabel.SetTextColor(textColor) - ui.footerLabel.SetBackgroundColor(textBgColor) + ui.footerLabel.SetTextColor(tcell.GetColor(ui.footerTextColor)) + ui.footerLabel.SetBackgroundColor(tcell.GetColor(ui.footerBackgroundColor)) ui.footerLabel.SetText(" No items to display. ") ui.footer = tview.NewFlex() @@ -205,6 +208,21 @@ func (ui *UI) SetSelectedBackgroundColor(color tcell.Color) { ui.selectedBackgroundColor = color } +// SetFooterTextColor sets the color for the footer text +func (ui *UI) SetFooterTextColor(color string) { + ui.footerTextColor = color +} + +// SetFooterBackgroundColor sets the color for the footer background +func (ui *UI) SetFooterBackgroundColor(color string) { + ui.footerBackgroundColor = color +} + +// SetFooterNumberColor sets the color for the footer number +func (ui *UI) SetFooterNumberColor(color string) { + ui.footerNumberColor = 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(maxLen int) { From c1397b5268197408e5d28c0265070dae7509d351 Mon Sep 17 00:00:00 2001 From: Daniel Milde Date: Sat, 28 Dec 2024 21:55:09 +0100 Subject: [PATCH 03/10] feat: configurable style for header --- cmd/gdu/app/app.go | 25 +++++++++++++++++++++++- cmd/gdu/main.go | 6 ++++++ tui/tui.go | 48 ++++++++++++++++++++++++++++++---------------- 3 files changed, 62 insertions(+), 17 deletions(-) diff --git a/cmd/gdu/app/app.go b/cmd/gdu/app/app.go index d1db635a4..8ae705141 100644 --- a/cmd/gdu/app/app.go +++ b/cmd/gdu/app/app.go @@ -89,6 +89,7 @@ type Style struct { ProgressModal ProgressModalOpts `yaml:"progress-modal"` UseOldSizeBar bool `yaml:"use-old-size-bar"` Footer FooterColorStyle `yaml:"footer"` + Header HeaderColorStyle `yaml:"header"` } // ProgressModalOpts defines options for progress modal @@ -102,13 +103,20 @@ type ColorStyle struct { BackgroundColor string `yaml:"background-color"` } -// ColorStyle defines styling of some item +// FooterColorStyle defines styling of footer type FooterColorStyle struct { TextColor string `yaml:"text-color"` BackgroundColor string `yaml:"background-color"` NumberColor string `yaml:"number-color"` } +// HeaderColorStyle defines styling of header +type HeaderColorStyle struct { + TextColor string `yaml:"text-color"` + BackgroundColor string `yaml:"background-color"` + Hidden bool `yaml:"hidden"` +} + // Sorting defines default sorting of items type Sorting struct { By string `yaml:"by"` @@ -285,6 +293,21 @@ func (a *App) createUI() (UI, error) { ui.SetFooterNumberColor(a.Flags.Style.Footer.NumberColor) }) } + if a.Flags.Style.Header.TextColor != "" { + opts = append(opts, func(ui *tui.UI) { + ui.SetHeaderTextColor(a.Flags.Style.Header.TextColor) + }) + } + if a.Flags.Style.Header.BackgroundColor != "" { + opts = append(opts, func(ui *tui.UI) { + ui.SetHeaderBackgroundColor(a.Flags.Style.Header.BackgroundColor) + }) + } + if a.Flags.Style.Header.Hidden { + opts = append(opts, func(ui *tui.UI) { + ui.SetHeaderHidden() + }) + } if a.Flags.Style.ProgressModal.CurrentItemNameMaxLen > 0 { opts = append(opts, func(ui *tui.UI) { ui.SetCurrentItemNameMaxLen(a.Flags.Style.ProgressModal.CurrentItemNameMaxLen) diff --git a/cmd/gdu/main.go b/cmd/gdu/main.go index 2c5275ff1..9fe9d0fa9 100644 --- a/cmd/gdu/main.go +++ b/cmd/gdu/main.go @@ -103,6 +103,12 @@ func initConfig() { if af.Style.Footer.NumberColor == "" { af.Style.Footer.NumberColor = "#FFFFFF" } + if af.Style.Header.BackgroundColor == "" { + af.Style.Header.BackgroundColor = "#2479D0" + } + if af.Style.Header.TextColor == "" { + af.Style.Header.TextColor = "#000000" + } } func setConfigFilePath() { diff --git a/tui/tui.go b/tui/tui.go index 1c2cbb139..f218d42f5 100644 --- a/tui/tui.go +++ b/tui/tui.go @@ -63,6 +63,9 @@ type UI struct { footerTextColor string footerBackgroundColor string footerNumberColor string + headerTextColor string + headerBackgroundColor string + headerHidden bool currentItemNameMaxLen int useOldSizeBar bool defaultSortBy string @@ -143,19 +146,10 @@ func CreateUI( ui.app.SetInputCapture(ui.keyPressed) ui.app.SetMouseCapture(ui.onMouse) - var textColor, textBgColor tcell.Color - if ui.UseColors { - textColor = tcell.NewRGBColor(0, 0, 0) - textBgColor = tcell.NewRGBColor(36, 121, 208) - } else { - textColor = tcell.NewRGBColor(0, 0, 0) - textBgColor = tcell.NewRGBColor(255, 255, 255) - } - ui.header = tview.NewTextView() ui.header.SetText(" gdu ~ Use arrow keys to navigate, press ? for help ") - ui.header.SetTextColor(textColor) - ui.header.SetBackgroundColor(textBgColor) + ui.header.SetTextColor(tcell.GetColor(ui.headerTextColor)) + ui.header.SetBackgroundColor(tcell.GetColor(ui.headerBackgroundColor)) ui.currentDirLabel = tview.NewTextView() ui.currentDirLabel.SetTextColor(tcell.ColorDefault) @@ -183,11 +177,18 @@ func CreateUI( ui.footer = tview.NewFlex() ui.footer.AddItem(ui.footerLabel, 0, 1, false) - ui.grid = tview.NewGrid().SetRows(1, 1, 0, 1).SetColumns(0) - ui.grid.AddItem(ui.header, 0, 0, 1, 1, 0, 0, false). - AddItem(ui.currentDirLabel, 1, 0, 1, 1, 0, 0, false). - AddItem(ui.table, 2, 0, 1, 1, 0, 0, true). - AddItem(ui.footer, 3, 0, 1, 1, 0, 0, false) + if ui.headerHidden { + ui.grid = tview.NewGrid().SetRows(1, 0, 1).SetColumns(0) + ui.grid.AddItem(ui.currentDirLabel, 0, 0, 1, 1, 0, 0, false). + AddItem(ui.table, 1, 0, 1, 1, 0, 0, true). + AddItem(ui.footer, 2, 0, 1, 1, 0, 0, false) + } else { + ui.grid = tview.NewGrid().SetRows(1, 1, 0, 1).SetColumns(0) + ui.grid.AddItem(ui.header, 0, 0, 1, 1, 0, 0, false). + AddItem(ui.currentDirLabel, 1, 0, 1, 1, 0, 0, false). + AddItem(ui.table, 2, 0, 1, 1, 0, 0, true). + AddItem(ui.footer, 3, 0, 1, 1, 0, 0, false) + } ui.pages = tview.NewPages(). AddPage("background", ui.grid, true, true) @@ -223,6 +224,21 @@ func (ui *UI) SetFooterNumberColor(color string) { ui.footerNumberColor = color } +// SetHeaderTextColor sets the color for the header text +func (ui *UI) SetHeaderTextColor(color string) { + ui.headerTextColor = color +} + +// SetHeaderBackgroundColor sets the color for the header background +func (ui *UI) SetHeaderBackgroundColor(color string) { + ui.headerBackgroundColor = color +} + +// SetHeaderHidden sets the flag to hide the header +func (ui *UI) SetHeaderHidden() { + ui.headerHidden = true +} + // SetCurrentItemNameMaxLen sets the maximum length of the path of the currently processed item // to be shown in the progress modal func (ui *UI) SetCurrentItemNameMaxLen(maxLen int) { From 07d846425351a20d3b0a155f347162b81fb4fed9 Mon Sep 17 00:00:00 2001 From: Daniel Milde Date: Sat, 28 Dec 2024 22:06:56 +0100 Subject: [PATCH 04/10] feat: configurable style for footer when listing devices --- tui/format.go | 1 - tui/show.go | 12 ++++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/tui/format.go b/tui/format.go index 3cc46d80a..6bfd82a29 100644 --- a/tui/format.go +++ b/tui/format.go @@ -11,7 +11,6 @@ import ( const ( blackOnWhite = "[black:white:-]" - blackOnBlue = "[#000000:#2479d0:-]" whiteOnBlack = "[white:black:-]" orangeBold = "[#e67100::b]" diff --git a/tui/show.go b/tui/show.go index 8a3124053..731d0eab8 100644 --- a/tui/show.go +++ b/tui/show.go @@ -224,8 +224,16 @@ func (ui *UI) showDevices() { var footerNumberColor, footerTextColor string if ui.UseColors { - footerNumberColor = "[#ffffff:#2479d0:b]" - footerTextColor = blackOnBlue + footerNumberColor = fmt.Sprintf( + "[%s:%s:b]", + ui.footerNumberColor, + ui.footerBackgroundColor, + ) + footerTextColor = fmt.Sprintf( + "[%s:%s:-]", + ui.footerTextColor, + ui.footerBackgroundColor, + ) } else { footerNumberColor = "[black:white:b]" footerTextColor = blackOnWhite From a4d4ece67c552976fd07ca42ff76c003de79ebd6 Mon Sep 17 00:00:00 2001 From: Daniel Milde Date: Sat, 28 Dec 2024 22:50:51 +0100 Subject: [PATCH 05/10] feat: configurable style for result row --- cmd/gdu/app/app.go | 27 ++++++++++++++++++++++----- cmd/gdu/main.go | 6 ++++++ tui/actions.go | 5 ++++- tui/format.go | 16 +++++++++------- tui/tui.go | 17 +++++++++++++++++ 5 files changed, 58 insertions(+), 13 deletions(-) diff --git a/cmd/gdu/app/app.go b/cmd/gdu/app/app.go index 8ae705141..250344d68 100644 --- a/cmd/gdu/app/app.go +++ b/cmd/gdu/app/app.go @@ -85,11 +85,12 @@ type Flags struct { // Style define style config type Style struct { - SelectedRow ColorStyle `yaml:"selected-row"` - ProgressModal ProgressModalOpts `yaml:"progress-modal"` - UseOldSizeBar bool `yaml:"use-old-size-bar"` - Footer FooterColorStyle `yaml:"footer"` - Header HeaderColorStyle `yaml:"header"` + SelectedRow ColorStyle `yaml:"selected-row"` + ProgressModal ProgressModalOpts `yaml:"progress-modal"` + UseOldSizeBar bool `yaml:"use-old-size-bar"` + Footer FooterColorStyle `yaml:"footer"` + Header HeaderColorStyle `yaml:"header"` + ResultRow ResultRowColorStyle `yaml:"result-row"` } // ProgressModalOpts defines options for progress modal @@ -117,6 +118,12 @@ type HeaderColorStyle struct { Hidden bool `yaml:"hidden"` } +// ResultRowColorStyle defines styling of result row +type ResultRowColorStyle struct { + NumberColor string `yaml:"number-color"` + DirectoryColor string `yaml:"directory-color"` +} + // Sorting defines default sorting of items type Sorting struct { By string `yaml:"by"` @@ -308,6 +315,16 @@ func (a *App) createUI() (UI, error) { ui.SetHeaderHidden() }) } + if a.Flags.Style.ResultRow.NumberColor != "" { + opts = append(opts, func(ui *tui.UI) { + ui.SetResultRowNumberColor(a.Flags.Style.ResultRow.NumberColor) + }) + } + if a.Flags.Style.ResultRow.DirectoryColor != "" { + opts = append(opts, func(ui *tui.UI) { + ui.SetResultRowDirectoryColor(a.Flags.Style.ResultRow.DirectoryColor) + }) + } if a.Flags.Style.ProgressModal.CurrentItemNameMaxLen > 0 { opts = append(opts, func(ui *tui.UI) { ui.SetCurrentItemNameMaxLen(a.Flags.Style.ProgressModal.CurrentItemNameMaxLen) diff --git a/cmd/gdu/main.go b/cmd/gdu/main.go index 9fe9d0fa9..37d05a27f 100644 --- a/cmd/gdu/main.go +++ b/cmd/gdu/main.go @@ -109,6 +109,12 @@ func initConfig() { if af.Style.Header.TextColor == "" { af.Style.Header.TextColor = "#000000" } + if af.Style.ResultRow.NumberColor == "" { + af.Style.ResultRow.NumberColor = "#e67100" + } + if af.Style.ResultRow.DirectoryColor == "" { + af.Style.ResultRow.DirectoryColor = "#3498db" + } } func setConfigFilePath() { diff --git a/tui/actions.go b/tui/actions.go index 16df0d0d9..2b8f23ff3 100644 --- a/tui/actions.go +++ b/tui/actions.go @@ -256,7 +256,10 @@ func (ui *UI) showInfo() { selectedFile := ui.table.GetCell(row, column).GetReference().(fs.Item) if ui.UseColors { - numberColor = orangeBold + numberColor = fmt.Sprintf( + "[%s::b]", + ui.resultRow.NumberColor, + ) } else { numberColor = defaultColorBold } diff --git a/tui/format.go b/tui/format.go index 6bfd82a29..581321f6f 100644 --- a/tui/format.go +++ b/tui/format.go @@ -13,9 +13,6 @@ const ( blackOnWhite = "[black:white:-]" whiteOnBlack = "[white:black:-]" - orangeBold = "[#e67100::b]" - blueBold = "[#3498db::b]" - defaultColor = "[-::]" defaultColorBold = "[::b]" ) @@ -36,8 +33,13 @@ func (ui *UI) formatFileRow(item fs.Item, maxUsage, maxSize int64, marked, ignor row := string(item.GetFlag()) + numberColor := fmt.Sprintf( + "[%s::b]", + ui.resultRow.NumberColor, + ) + if ui.UseColors && !marked && !ignored { - row += orangeBold + row += numberColor } else { row += defaultColorBold } @@ -56,7 +58,7 @@ func (ui *UI) formatFileRow(item fs.Item, maxUsage, maxSize int64, marked, ignor if ui.showItemCount { if ui.UseColors && !marked && !ignored { - row += orangeBold + row += numberColor } else { row += defaultColorBold } @@ -65,7 +67,7 @@ func (ui *UI) formatFileRow(item fs.Item, maxUsage, maxSize int64, marked, ignor if ui.showMtime { if ui.UseColors && !marked && !ignored { - row += orangeBold + row += numberColor } else { row += defaultColorBold } @@ -86,7 +88,7 @@ func (ui *UI) formatFileRow(item fs.Item, maxUsage, maxSize int64, marked, ignor if item.IsDir() { if ui.UseColors && !marked && !ignored { - row += blueBold + "/" + row += fmt.Sprintf("[%s::b]/", ui.resultRow.DirectoryColor) } else { row += defaultColorBold + "/" } diff --git a/tui/tui.go b/tui/tui.go index f218d42f5..c296d08d3 100644 --- a/tui/tui.go +++ b/tui/tui.go @@ -66,6 +66,7 @@ type UI struct { headerTextColor string headerBackgroundColor string headerHidden bool + resultRow ResultRow currentItemNameMaxLen int useOldSizeBar bool defaultSortBy string @@ -87,6 +88,12 @@ type deleteQueueItem struct { shouldEmpty bool } +// ResultRow is a struct for a row in the result table +type ResultRow struct { + NumberColor string + DirectoryColor string +} + // Option is optional function customizing the bahaviour of UI type Option func(ui *UI) @@ -239,6 +246,16 @@ func (ui *UI) SetHeaderHidden() { ui.headerHidden = true } +// SetResultRowDirectoryColor sets the color for the result row directory +func (ui *UI) SetResultRowDirectoryColor(color string) { + ui.resultRow.DirectoryColor = color +} + +// SetResultRowNumberColor sets the color for the result row number +func (ui *UI) SetResultRowNumberColor(color string) { + ui.resultRow.NumberColor = 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(maxLen int) { From 172b22ea1189e51c744bbe538005917c42fd3507 Mon Sep 17 00:00:00 2001 From: Daniel Milde Date: Sat, 28 Dec 2024 23:10:16 +0100 Subject: [PATCH 06/10] refactor: shorten methods --- cmd/gdu/app/app.go | 199 +++++++++++++++++++++++---------------------- tui/tui.go | 21 +++-- 2 files changed, 115 insertions(+), 105 deletions(-) diff --git a/cmd/gdu/app/app.go b/cmd/gdu/app/app.go index 250344d68..135a4a7b3 100644 --- a/cmd/gdu/app/app.go +++ b/cmd/gdu/app/app.go @@ -273,103 +273,7 @@ func (a *App) createUI() (UI, error) { } ui = stdoutUI default: - var opts []tui.Option - - if a.Flags.Style.SelectedRow.TextColor != "" { - opts = append(opts, func(ui *tui.UI) { - ui.SetSelectedTextColor(tcell.GetColor(a.Flags.Style.SelectedRow.TextColor)) - }) - } - if a.Flags.Style.SelectedRow.BackgroundColor != "" { - opts = append(opts, func(ui *tui.UI) { - ui.SetSelectedBackgroundColor(tcell.GetColor(a.Flags.Style.SelectedRow.BackgroundColor)) - }) - } - if a.Flags.Style.Footer.TextColor != "" { - opts = append(opts, func(ui *tui.UI) { - ui.SetFooterTextColor(a.Flags.Style.Footer.TextColor) - }) - } - if a.Flags.Style.Footer.BackgroundColor != "" { - opts = append(opts, func(ui *tui.UI) { - ui.SetFooterBackgroundColor(a.Flags.Style.Footer.BackgroundColor) - }) - } - if a.Flags.Style.Footer.NumberColor != "" { - opts = append(opts, func(ui *tui.UI) { - ui.SetFooterNumberColor(a.Flags.Style.Footer.NumberColor) - }) - } - if a.Flags.Style.Header.TextColor != "" { - opts = append(opts, func(ui *tui.UI) { - ui.SetHeaderTextColor(a.Flags.Style.Header.TextColor) - }) - } - if a.Flags.Style.Header.BackgroundColor != "" { - opts = append(opts, func(ui *tui.UI) { - ui.SetHeaderBackgroundColor(a.Flags.Style.Header.BackgroundColor) - }) - } - if a.Flags.Style.Header.Hidden { - opts = append(opts, func(ui *tui.UI) { - ui.SetHeaderHidden() - }) - } - if a.Flags.Style.ResultRow.NumberColor != "" { - opts = append(opts, func(ui *tui.UI) { - ui.SetResultRowNumberColor(a.Flags.Style.ResultRow.NumberColor) - }) - } - if a.Flags.Style.ResultRow.DirectoryColor != "" { - opts = append(opts, func(ui *tui.UI) { - ui.SetResultRowDirectoryColor(a.Flags.Style.ResultRow.DirectoryColor) - }) - } - if a.Flags.Style.ProgressModal.CurrentItemNameMaxLen > 0 { - opts = append(opts, func(ui *tui.UI) { - ui.SetCurrentItemNameMaxLen(a.Flags.Style.ProgressModal.CurrentItemNameMaxLen) - }) - } - if a.Flags.Style.UseOldSizeBar || a.Flags.NoUnicode { - opts = append(opts, func(ui *tui.UI) { - ui.UseOldSizeBar() - }) - } - if a.Flags.Sorting.Order != "" || a.Flags.Sorting.By != "" { - opts = append(opts, func(ui *tui.UI) { - ui.SetDefaultSorting(a.Flags.Sorting.By, a.Flags.Sorting.Order) - }) - } - if a.Flags.ChangeCwd { - opts = append(opts, func(ui *tui.UI) { - ui.SetChangeCwdFn(os.Chdir) - }) - } - if a.Flags.ShowItemCount { - opts = append(opts, func(ui *tui.UI) { - ui.SetShowItemCount() - }) - } - if a.Flags.ShowMTime { - opts = append(opts, func(ui *tui.UI) { - ui.SetShowMTime() - }) - } - if a.Flags.NoDelete { - opts = append(opts, func(ui *tui.UI) { - ui.SetNoDelete() - }) - } - if a.Flags.DeleteInBackground { - opts = append(opts, func(ui *tui.UI) { - ui.SetDeleteInBackground() - }) - } - if a.Flags.DeleteInParallel { - opts = append(opts, func(ui *tui.UI) { - ui.SetDeleteInParallel() - }) - } + opts := a.getOptions() ui = tui.CreateUI( a.TermApp, @@ -394,6 +298,107 @@ func (a *App) createUI() (UI, error) { return ui, nil } +func (a *App) getOptions() []tui.Option { + var opts []tui.Option + + if a.Flags.Style.SelectedRow.TextColor != "" { + opts = append(opts, func(ui *tui.UI) { + ui.SetSelectedTextColor(tcell.GetColor(a.Flags.Style.SelectedRow.TextColor)) + }) + } + if a.Flags.Style.SelectedRow.BackgroundColor != "" { + opts = append(opts, func(ui *tui.UI) { + ui.SetSelectedBackgroundColor(tcell.GetColor(a.Flags.Style.SelectedRow.BackgroundColor)) + }) + } + if a.Flags.Style.Footer.TextColor != "" { + opts = append(opts, func(ui *tui.UI) { + ui.SetFooterTextColor(a.Flags.Style.Footer.TextColor) + }) + } + if a.Flags.Style.Footer.BackgroundColor != "" { + opts = append(opts, func(ui *tui.UI) { + ui.SetFooterBackgroundColor(a.Flags.Style.Footer.BackgroundColor) + }) + } + if a.Flags.Style.Footer.NumberColor != "" { + opts = append(opts, func(ui *tui.UI) { + ui.SetFooterNumberColor(a.Flags.Style.Footer.NumberColor) + }) + } + if a.Flags.Style.Header.TextColor != "" { + opts = append(opts, func(ui *tui.UI) { + ui.SetHeaderTextColor(a.Flags.Style.Header.TextColor) + }) + } + if a.Flags.Style.Header.BackgroundColor != "" { + opts = append(opts, func(ui *tui.UI) { + ui.SetHeaderBackgroundColor(a.Flags.Style.Header.BackgroundColor) + }) + } + if a.Flags.Style.Header.Hidden { + opts = append(opts, func(ui *tui.UI) { + ui.SetHeaderHidden() + }) + } + if a.Flags.Style.ResultRow.NumberColor != "" { + opts = append(opts, func(ui *tui.UI) { + ui.SetResultRowNumberColor(a.Flags.Style.ResultRow.NumberColor) + }) + } + if a.Flags.Style.ResultRow.DirectoryColor != "" { + opts = append(opts, func(ui *tui.UI) { + ui.SetResultRowDirectoryColor(a.Flags.Style.ResultRow.DirectoryColor) + }) + } + if a.Flags.Style.ProgressModal.CurrentItemNameMaxLen > 0 { + opts = append(opts, func(ui *tui.UI) { + ui.SetCurrentItemNameMaxLen(a.Flags.Style.ProgressModal.CurrentItemNameMaxLen) + }) + } + if a.Flags.Style.UseOldSizeBar || a.Flags.NoUnicode { + opts = append(opts, func(ui *tui.UI) { + ui.UseOldSizeBar() + }) + } + if a.Flags.Sorting.Order != "" || a.Flags.Sorting.By != "" { + opts = append(opts, func(ui *tui.UI) { + ui.SetDefaultSorting(a.Flags.Sorting.By, a.Flags.Sorting.Order) + }) + } + if a.Flags.ChangeCwd { + opts = append(opts, func(ui *tui.UI) { + ui.SetChangeCwdFn(os.Chdir) + }) + } + if a.Flags.ShowItemCount { + opts = append(opts, func(ui *tui.UI) { + ui.SetShowItemCount() + }) + } + if a.Flags.ShowMTime { + opts = append(opts, func(ui *tui.UI) { + ui.SetShowMTime() + }) + } + if a.Flags.NoDelete { + opts = append(opts, func(ui *tui.UI) { + ui.SetNoDelete() + }) + } + if a.Flags.DeleteInBackground { + opts = append(opts, func(ui *tui.UI) { + ui.SetDeleteInBackground() + }) + } + if a.Flags.DeleteInParallel { + opts = append(opts, func(ui *tui.UI) { + ui.SetDeleteInParallel() + }) + } + return opts +} + func (a *App) setNoCross(path string) error { if a.Flags.NoCross { mounts, err := a.Getter.GetMounts() diff --git a/tui/tui.go b/tui/tui.go index c296d08d3..63cf79aa9 100644 --- a/tui/tui.go +++ b/tui/tui.go @@ -184,6 +184,19 @@ func CreateUI( ui.footer = tview.NewFlex() ui.footer.AddItem(ui.footerLabel, 0, 1, false) + ui.createGrid() + + ui.pages = tview.NewPages(). + AddPage("background", ui.grid, true, true) + ui.pages.SetBackgroundColor(tcell.ColorDefault) + + ui.app.SetRoot(ui.pages, true) + + return ui +} + +// createGrid creates the main grid layout +func (ui *UI) createGrid() { if ui.headerHidden { ui.grid = tview.NewGrid().SetRows(1, 0, 1).SetColumns(0) ui.grid.AddItem(ui.currentDirLabel, 0, 0, 1, 1, 0, 0, false). @@ -196,14 +209,6 @@ func CreateUI( AddItem(ui.table, 2, 0, 1, 1, 0, 0, true). AddItem(ui.footer, 3, 0, 1, 1, 0, 0, false) } - - ui.pages = tview.NewPages(). - AddPage("background", ui.grid, true, true) - ui.pages.SetBackgroundColor(tcell.ColorDefault) - - ui.app.SetRoot(ui.pages, true) - - return ui } // SetSelectedTextColor sets the color for the highighted selected text From 64c79223440e603abc004b3c7afe54418601f601 Mon Sep 17 00:00:00 2001 From: Daniel Milde Date: Sun, 29 Dec 2024 17:45:37 +0100 Subject: [PATCH 07/10] fix: call correct print func --- stdout/stdout.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdout/stdout.go b/stdout/stdout.go index 84dfcacef..8e7538f05 100644 --- a/stdout/stdout.go +++ b/stdout/stdout.go @@ -262,7 +262,7 @@ func (ui *UI) printItem(file fs.Item) { lineFormat, string(file.GetFlag()), ui.formatSize(size), - ui.blue.Sprintf("/"+file.GetName())) + ui.blue.Sprint("/"+file.GetName())) } else { fmt.Fprintf(ui.output, lineFormat, From 49851d3d72ceab3a9194c63de0bc29333fa9c66b Mon Sep 17 00:00:00 2001 From: Daniel Milde Date: Sun, 29 Dec 2024 17:46:08 +0100 Subject: [PATCH 08/10] ci: bump minimal go version --- .github/workflows/test.yml | 8 ++++---- go.mod | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c70bf21af..a4bea1463 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,18 +14,18 @@ jobs: - name: Install Go uses: actions/setup-go@v5 with: - go-version: 1.18.x + go-version: 1.23.x - name: Checkout code uses: actions/checkout@v4 - name: Run linters uses: golangci/golangci-lint-action@v5 with: - version: v1.57.2 + version: v1.62.2 test: strategy: matrix: - go-version: [1.18.x, 1.19.x, 1.20.x, 1.21.x, 1.22.x] + go-version: [1.21.x, 1.22.x, 1.23.x] platform: [ubuntu-latest] include: - go-version: 1.22.x @@ -49,7 +49,7 @@ jobs: if: success() uses: actions/setup-go@v5 with: - go-version: 1.18.x + go-version: 1.23.x - name: Checkout code uses: actions/checkout@v4 - name: Calc coverage diff --git a/go.mod b/go.mod index 22c1d55ab..3c9bbead4 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/dundee/gdu/v5 -go 1.18 +go 1.21 require ( github.com/dgraph-io/badger/v3 v3.2103.2 From a6fc922b08366220f92f42ca5379e40715643a9c Mon Sep 17 00:00:00 2001 From: Daniel Milde Date: Sun, 29 Dec 2024 17:46:21 +0100 Subject: [PATCH 09/10] refactor: remove unused min func --- tui/utils.go | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tui/utils.go b/tui/utils.go index 6403dbd11..500eafb4b 100644 --- a/tui/utils.go +++ b/tui/utils.go @@ -60,13 +60,6 @@ func getUsageGraphOld(part int) string { return graph } -func min(a, b int) int { - if a < b { - return a - } - return b -} - func modal(p tview.Primitive, width, height int) tview.Primitive { return tview.NewFlex(). AddItem(nil, 0, 1, false). From 2c8c1a47cdfb230c67d2cfc235fa10eec479c557 Mon Sep 17 00:00:00 2001 From: Daniel Milde Date: Sun, 29 Dec 2024 17:55:59 +0100 Subject: [PATCH 10/10] test: cover new style options --- cmd/gdu/app/app_test.go | 14 ++++++++++++++ tui/tui_test.go | 36 +++++++++++++++++++++++------------- 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/cmd/gdu/app/app_test.go b/cmd/gdu/app/app_test.go index 55b428ac1..377a140f4 100644 --- a/cmd/gdu/app/app_test.go +++ b/cmd/gdu/app/app_test.go @@ -275,6 +275,20 @@ func TestAnalyzePathWithStyle(t *testing.T) { ProgressModal: ProgressModalOpts{ CurrentItemNameMaxLen: 10, }, + Footer: FooterColorStyle{ + TextColor: "black", + BackgroundColor: "red", + NumberColor: "white", + }, + Header: HeaderColorStyle{ + TextColor: "black", + BackgroundColor: "red", + Hidden: true, + }, + ResultRow: ResultRowColorStyle{ + NumberColor: "orange", + DirectoryColor: "blue", + }, UseOldSizeBar: true, }, }, diff --git a/tui/tui_test.go b/tui/tui_test.go index a3a7503b0..2b4274a42 100644 --- a/tui/tui_test.go +++ b/tui/tui_test.go @@ -700,28 +700,38 @@ func TestMin(t *testing.T) { assert.Equal(t, 3, min(4, 3)) } -func TestSetSelectedBackgroundColor(t *testing.T) { +func TestSetStyles(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.SetSelectedBackgroundColor(tcell.ColorRed) - - assert.Equal(t, ui.selectedBackgroundColor, tcell.ColorRed) -} - -func TestSetSelectedTextColor(t *testing.T) { - simScreen := testapp.CreateSimScreen() - defer simScreen.Fini() + opts := []Option{} + opts = append(opts, func(ui *UI) { + ui.SetHeaderHidden() + }) app := testapp.CreateMockedApp(true) - ui := CreateUI(app, simScreen, &bytes.Buffer{}, false, true, false, false, false) + ui := CreateUI(app, simScreen, &bytes.Buffer{}, false, true, false, false, false, opts...) + ui.SetSelectedBackgroundColor(tcell.ColorRed) ui.SetSelectedTextColor(tcell.ColorRed) + ui.SetFooterTextColor("red") + ui.SetFooterBackgroundColor("red") + ui.SetFooterNumberColor("red") + ui.SetHeaderTextColor("red") + ui.SetHeaderBackgroundColor("red") + ui.SetResultRowDirectoryColor("red") + ui.SetResultRowNumberColor("red") + assert.Equal(t, ui.selectedBackgroundColor, tcell.ColorRed) assert.Equal(t, ui.selectedTextColor, tcell.ColorRed) + assert.Equal(t, ui.footerTextColor, "red") + assert.Equal(t, ui.footerBackgroundColor, "red") + assert.Equal(t, ui.footerNumberColor, "red") + assert.Equal(t, ui.headerTextColor, "red") + assert.Equal(t, ui.headerBackgroundColor, "red") + assert.Equal(t, ui.headerHidden, true) + assert.Equal(t, ui.resultRow.DirectoryColor, "red") + assert.Equal(t, ui.resultRow.NumberColor, "red") } func TestSetCurrentItemNameMaxLen(t *testing.T) {