theme.go

  1package tui
  2
  3import (
  4	"charm.land/bubbles/v2/textarea"
  5	"charm.land/bubbles/v2/textinput"
  6	tea "charm.land/bubbletea/v2"
  7	"charm.land/lipgloss/v2"
  8	"github.com/floatpane/matcha/theme"
  9)
 10
 11// RebuildStyles updates all package-level style variables to match the active theme.
 12// This must be called after theme.SetTheme() and at startup.
 13func RebuildStyles() {
 14	t := theme.ActiveTheme
 15
 16	// styles.go
 17	DialogBoxStyle = lipgloss.NewStyle().
 18		Border(lipgloss.RoundedBorder()).
 19		BorderForeground(t.AccentDark).
 20		Padding(1, 2).
 21		BorderTop(true).
 22		BorderLeft(true).
 23		BorderRight(true).
 24		BorderBottom(true)
 25
 26	HelpStyle = lipgloss.NewStyle().Foreground(t.Secondary)
 27	TipStyle = lipgloss.NewStyle().Foreground(t.Tip).Italic(true)
 28	SuccessStyle = lipgloss.NewStyle().Foreground(t.Accent).Bold(true)
 29	InfoStyle = lipgloss.NewStyle().Foreground(t.Accent).Bold(true)
 30
 31	H1Style = lipgloss.NewStyle().
 32		Foreground(t.Accent).
 33		Bold(true).
 34		Align(lipgloss.Center)
 35
 36	H2Style = lipgloss.NewStyle().
 37		Foreground(t.Accent).
 38		Bold(false).
 39		Align(lipgloss.Center)
 40
 41	// choice.go
 42	titleStyle = lipgloss.NewStyle().Foreground(t.AccentText).Background(t.AccentDark).Padding(0, 1)
 43	logoStyle = lipgloss.NewStyle().Foreground(t.Accent)
 44	listHeader = lipgloss.NewStyle().Foreground(t.SubtleText).PaddingBottom(1)
 45	itemStyle = lipgloss.NewStyle().PaddingLeft(2)
 46	selectedItemStyle = lipgloss.NewStyle().PaddingLeft(2).Foreground(t.Accent)
 47
 48	// settings.go
 49	accountItemStyle = lipgloss.NewStyle().PaddingLeft(2)
 50	selectedAccountItemStyle = lipgloss.NewStyle().PaddingLeft(2).Foreground(t.Accent)
 51	accountEmailStyle = lipgloss.NewStyle().Foreground(t.Secondary)
 52	dangerStyle = lipgloss.NewStyle().Foreground(t.Danger)
 53	settingsFocusedStyle = lipgloss.NewStyle().Foreground(t.Accent)
 54	settingsBlurredStyle = lipgloss.NewStyle().Foreground(t.Secondary)
 55
 56	// composer.go
 57	suggestionStyle = lipgloss.NewStyle().Foreground(t.Secondary)
 58	selectedSuggestionStyle = lipgloss.NewStyle().Foreground(t.Accent).Bold(true)
 59	suggestionBoxStyle = lipgloss.NewStyle().Border(lipgloss.RoundedBorder()).BorderForeground(t.Secondary).Padding(0, 1)
 60	focusedStyle = lipgloss.NewStyle().Foreground(t.Accent)
 61	blurredStyle = lipgloss.NewStyle().Foreground(t.Secondary)
 62	noStyle = lipgloss.NewStyle()
 63	helpStyle = lipgloss.NewStyle().Foreground(t.SubtleText)
 64	emailRecipientStyle = lipgloss.NewStyle().Foreground(t.Accent).Bold(true)
 65	attachmentStyle = lipgloss.NewStyle().PaddingLeft(4).Foreground(t.Secondary)
 66	fromSelectorStyle = lipgloss.NewStyle().Foreground(t.Accent)
 67	smimeToggleStyle = lipgloss.NewStyle().PaddingLeft(4).Foreground(t.Secondary)
 68
 69	// inbox.go
 70	tabStyle = lipgloss.NewStyle().Padding(0, 2)
 71	activeTabStyle = lipgloss.NewStyle().Padding(0, 2).Foreground(t.Accent).Bold(true).Underline(true)
 72	tabBarStyle = lipgloss.NewStyle().BorderStyle(lipgloss.NormalBorder()).BorderBottom(true).PaddingBottom(1).MarginBottom(1)
 73	dateStyle = lipgloss.NewStyle().Foreground(t.MutedText)
 74	unreadEmailStyle = lipgloss.NewStyle().Foreground(t.Accent).Bold(true)
 75	readEmailStyle = lipgloss.NewStyle().Foreground(t.Secondary)
 76	visualSelectedStyle = lipgloss.NewStyle().Background(t.AccentDark).Foreground(t.AccentText)
 77
 78	// folder_inbox.go
 79	sidebarStyle = lipgloss.NewStyle().
 80		Width(sidebarWidth).
 81		BorderStyle(lipgloss.NormalBorder()).
 82		BorderRight(true).
 83		PaddingRight(1).
 84		PaddingLeft(1)
 85	sidebarTitleStyle = lipgloss.NewStyle().
 86		Foreground(t.Accent).
 87		Bold(true).
 88		PaddingBottom(1)
 89	folderStyle = lipgloss.NewStyle().
 90		PaddingLeft(1).
 91		PaddingRight(1)
 92	activeFolderStyle = lipgloss.NewStyle().
 93		PaddingLeft(1).
 94		PaddingRight(1).
 95		Background(t.Accent).
 96		Foreground(t.Contrast).
 97		Bold(true)
 98	moveOverlayStyle = lipgloss.NewStyle().
 99		Border(lipgloss.RoundedBorder()).
100		BorderForeground(t.AccentDark).
101		Padding(1, 2)
102	moveOverlayTitleStyle = lipgloss.NewStyle().
103		Foreground(t.Accent).
104		Bold(true).
105		PaddingBottom(1)
106	moveItemStyle = lipgloss.NewStyle().
107		PaddingLeft(1)
108	moveSelectedItemStyle = lipgloss.NewStyle().
109		PaddingLeft(1).
110		Foreground(t.Accent).
111		Bold(true)
112
113	// filepicker.go
114	filePickerItemStyle = lipgloss.NewStyle().PaddingLeft(2)
115	filePickerSelectedItemStyle = lipgloss.NewStyle().PaddingLeft(2).Foreground(t.Accent)
116	directoryStyle = lipgloss.NewStyle().Foreground(t.Directory)
117	fileSizeStyle = lipgloss.NewStyle().Foreground(t.Secondary)
118}
119
120// ThemedTextInputStyles returns textinput.Styles using the active theme colors.
121func ThemedTextInputStyles() textinput.Styles {
122	t := theme.ActiveTheme
123	return textinput.Styles{
124		Focused: textinput.StyleState{
125			Placeholder: lipgloss.NewStyle().Foreground(t.DimText),
126			Suggestion:  lipgloss.NewStyle().Foreground(t.DimText),
127			Prompt:      lipgloss.NewStyle().Foreground(t.AccentText),
128			Text:        lipgloss.NewStyle(),
129		},
130		Blurred: textinput.StyleState{
131			Placeholder: lipgloss.NewStyle().Foreground(t.DimText),
132			Suggestion:  lipgloss.NewStyle().Foreground(t.DimText),
133			Prompt:      lipgloss.NewStyle().Foreground(t.MutedText),
134			Text:        lipgloss.NewStyle().Foreground(t.DimText),
135		},
136		Cursor: textinput.CursorStyle{
137			Color: t.AccentText,
138			Shape: tea.CursorBlock,
139			Blink: true,
140		},
141	}
142}
143
144// ThemedTextAreaStyles returns textarea.Styles using the active theme colors.
145func ThemedTextAreaStyles() textarea.Styles {
146	t := theme.ActiveTheme
147	return textarea.Styles{
148		Focused: textarea.StyleState{
149			Base:             lipgloss.NewStyle(),
150			CursorLine:       lipgloss.NewStyle(),
151			CursorLineNumber: lipgloss.NewStyle().Foreground(t.MutedText),
152			EndOfBuffer:      lipgloss.NewStyle().Foreground(t.Secondary),
153			LineNumber:       lipgloss.NewStyle().Foreground(t.MutedText),
154			Placeholder:      lipgloss.NewStyle().Foreground(t.DimText),
155			Prompt:           lipgloss.NewStyle().Foreground(t.AccentText),
156			Text:             lipgloss.NewStyle(),
157		},
158		Blurred: textarea.StyleState{
159			Base:             lipgloss.NewStyle(),
160			CursorLine:       lipgloss.NewStyle().Foreground(t.DimText),
161			CursorLineNumber: lipgloss.NewStyle().Foreground(t.MutedText),
162			EndOfBuffer:      lipgloss.NewStyle().Foreground(t.Secondary),
163			LineNumber:       lipgloss.NewStyle().Foreground(t.MutedText),
164			Placeholder:      lipgloss.NewStyle().Foreground(t.DimText),
165			Prompt:           lipgloss.NewStyle().Foreground(t.MutedText),
166			Text:             lipgloss.NewStyle().Foreground(t.DimText),
167		},
168		Cursor: textarea.CursorStyle{
169			Color: t.AccentText,
170			Shape: tea.CursorBlock,
171			Blink: true,
172		},
173	}
174}