Skip to content

Commit 6d10e0b

Browse files
authored
feat: improve UI color scheme for better readability across terminal themes
Updates the UI theme system and improves visual consistency and accessibility across different terminal themes. The main changes include refactoring how colors are handled, updating component styles for better visibility, and ensuring that global styles adapt to the user's terminal settings.
1 parent aeee3b9 commit 6d10e0b

File tree

3 files changed

+82
-16
lines changed

3 files changed

+82
-16
lines changed

internal/ui/components/modal.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package components
22

33
import (
44
"bbrew/internal/ui/theme"
5+
6+
"github.com/gdamore/tcell/v2"
57
"github.com/rivo/tview"
68
)
79

@@ -11,11 +13,19 @@ type Modal struct {
1113
}
1214

1315
func NewModal(theme *theme.Theme) *Modal {
16+
// Use green background with black text for activated button
17+
// Black text ensures consistent visibility across all terminal themes
18+
activatedStyle := tcell.StyleDefault.
19+
Background(theme.SuccessColor).
20+
Foreground(tcell.ColorBlack).
21+
Bold(true)
22+
1423
modal := tview.NewModal().
1524
SetBackgroundColor(theme.ModalBgColor).
1625
SetTextColor(theme.DefaultTextColor).
1726
SetButtonBackgroundColor(theme.ButtonBgColor).
18-
SetButtonTextColor(theme.ButtonTextColor)
27+
SetButtonTextColor(theme.ButtonTextColor).
28+
SetButtonActivatedStyle(activatedStyle)
1929

2030
return &Modal{
2131
view: modal,
@@ -31,7 +41,8 @@ func (m *Modal) Build(text string, confirmFunc func(), cancelFunc func()) *tview
3141
m.view.ClearButtons()
3242
m.view.
3343
SetText(text).
34-
AddButtons([]string{"Confirm", "Cancel"}).
44+
// Add padding to button labels with spaces for better visual appearance
45+
AddButtons([]string{" Confirm ", " Cancel "}).
3546
SetDoneFunc(func(buttonIndex int, _ string) {
3647
switch buttonIndex {
3748
case 0:

internal/ui/components/table.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package components
22

33
import (
44
"bbrew/internal/ui/theme"
5+
6+
"github.com/gdamore/tcell/v2"
57
"github.com/rivo/tview"
68
)
79

@@ -18,6 +20,10 @@ func NewTable(theme *theme.Theme) *Table {
1820
table.view.SetBorders(false)
1921
table.view.SetSelectable(true, false)
2022
table.view.SetFixed(1, 0)
23+
24+
// Use reverse video for selection to ensure visibility on any terminal theme
25+
table.view.SetSelectedStyle(tcell.StyleDefault.Reverse(true))
26+
2127
return table
2228
}
2329

internal/ui/theme/theme.go

Lines changed: 63 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package theme
22

3-
import "github.com/gdamore/tcell/v2"
3+
import (
4+
"github.com/gdamore/tcell/v2"
5+
"github.com/rivo/tview"
6+
)
47

58
type Theme struct {
9+
// Application-specific colors
610
DefaultTextColor tcell.Color
711
DefaultBgColor tcell.Color
812
WarningColor tcell.Color
@@ -18,24 +22,69 @@ type Theme struct {
1822
LegendColor tcell.Color
1923
TableHeaderColor tcell.Color
2024
SearchLabelColor tcell.Color
25+
26+
// tview global styles (mapped to tview.Styles)
27+
PrimitiveBackgroundColor tcell.Color
28+
ContrastBackgroundColor tcell.Color
29+
MoreContrastBackgroundColor tcell.Color
30+
BorderColor tcell.Color
31+
GraphicsColor tcell.Color
32+
PrimaryTextColor tcell.Color
33+
SecondaryTextColor tcell.Color
34+
TertiaryTextColor tcell.Color
35+
InverseTextColor tcell.Color
36+
ContrastSecondaryTextColor tcell.Color
2137
}
2238

2339
func NewTheme() *Theme {
24-
return &Theme{
25-
DefaultTextColor: tcell.ColorWhite,
26-
DefaultBgColor: tcell.ColorBlack,
27-
WarningColor: tcell.ColorYellow,
28-
SuccessColor: tcell.ColorGreen,
29-
ErrorColor: tcell.ColorRed,
30-
31-
TitleColor: tcell.ColorMediumVioletRed,
40+
theme := &Theme{
41+
// Application-specific colors
42+
DefaultTextColor: tcell.ColorDefault,
43+
DefaultBgColor: tcell.ColorDefault,
44+
45+
// Use standard ANSI colors that work well on both light and dark themes
46+
WarningColor: tcell.ColorYellow,
47+
SuccessColor: tcell.ColorGreen,
48+
ErrorColor: tcell.ColorRed,
49+
50+
// Component colors
51+
TitleColor: tcell.ColorPurple,
3252
LabelColor: tcell.ColorYellow,
33-
ButtonBgColor: tcell.ColorGray,
34-
ButtonTextColor: tcell.ColorWhite,
53+
ButtonBgColor: tcell.ColorDefault,
54+
ButtonTextColor: tcell.ColorDefault,
3555

36-
ModalBgColor: tcell.ColorDarkSlateGray,
37-
LegendColor: tcell.ColorWhite,
56+
ModalBgColor: tcell.ColorDefault,
57+
LegendColor: tcell.ColorDefault,
3858
TableHeaderColor: tcell.ColorBlue,
39-
SearchLabelColor: tcell.ColorMediumVioletRed,
59+
SearchLabelColor: tcell.ColorPurple,
60+
61+
// tview global styles - use terminal default colors for better compatibility
62+
// By default, tview uses hardcoded colors (like tcell.ColorBlack) which don't
63+
// adapt to the terminal's theme. We set them all to ColorDefault.
64+
PrimitiveBackgroundColor: tcell.ColorDefault,
65+
ContrastBackgroundColor: tcell.ColorDefault,
66+
MoreContrastBackgroundColor: tcell.ColorDefault,
67+
BorderColor: tcell.ColorDefault,
68+
GraphicsColor: tcell.ColorDefault,
69+
PrimaryTextColor: tcell.ColorDefault,
70+
SecondaryTextColor: tcell.ColorDefault,
71+
TertiaryTextColor: tcell.ColorDefault,
72+
InverseTextColor: tcell.ColorDefault,
73+
ContrastSecondaryTextColor: tcell.ColorDefault,
4074
}
75+
76+
// Apply theme to tview global styles
77+
tview.Styles.PrimitiveBackgroundColor = theme.PrimitiveBackgroundColor
78+
tview.Styles.ContrastBackgroundColor = theme.ContrastBackgroundColor
79+
tview.Styles.MoreContrastBackgroundColor = theme.MoreContrastBackgroundColor
80+
tview.Styles.BorderColor = theme.BorderColor
81+
tview.Styles.TitleColor = theme.TitleColor
82+
tview.Styles.GraphicsColor = theme.GraphicsColor
83+
tview.Styles.PrimaryTextColor = theme.PrimaryTextColor
84+
tview.Styles.SecondaryTextColor = theme.SecondaryTextColor
85+
tview.Styles.TertiaryTextColor = theme.TertiaryTextColor
86+
tview.Styles.InverseTextColor = theme.InverseTextColor
87+
tview.Styles.ContrastSecondaryTextColor = theme.ContrastSecondaryTextColor
88+
89+
return theme
4190
}

0 commit comments

Comments
 (0)