tui: shared terminal-UI kernel as nested module yetano.dev/yetano/core/tui
Themes (slate/dialog/midnight) and their lipgloss styles, Paint/Outer, ListState and the text helpers that yet, yavebu and yalsh menuconfig each carried as a hand-kept copy (yavebu's had already drifted). Values are yet's (grey slate); Paint is menuconfig's profile-aware version. Own go.mod and tui/vX.Y.Z tags keep Charm out of the main module. Programs are not switched yet; tui/README.md has the steps. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8c63d42a27
commit
88d37410f7
11 files changed
+729
-7
No files matched your search
+237
@@ -0,0 +1,237 @@
|
||||
// Package tui is the shared kernel of the Yetano terminal UIs (Charm v2):
|
||||
// the three color themes and their lipgloss styles, the paint/outer layout
|
||||
// helpers, the filtered list state and the text helpers that yet's TUI,
|
||||
// yavebu's TUI and yalsh's menuconfig each carried as a hand-kept copy.
|
||||
// It deliberately holds no app shell, menus or screens -- those still
|
||||
// differ per program (see README.md).
|
||||
package tui
|
||||
|
||||
import (
|
||||
"image/color"
|
||||
|
||||
"charm.land/lipgloss/v2"
|
||||
)
|
||||
|
||||
// Theme is one color scheme; every surface of a Yetano TUI takes its colors
|
||||
// from these roles.
|
||||
type Theme struct {
|
||||
Name string
|
||||
Background color.Color
|
||||
Panel color.Color
|
||||
PanelAlt color.Color
|
||||
PanelBorder color.Color
|
||||
Text color.Color
|
||||
Muted color.Color
|
||||
Accent color.Color
|
||||
AccentText color.Color
|
||||
Selected color.Color
|
||||
SelectedText color.Color
|
||||
Success color.Color
|
||||
Warning color.Color
|
||||
}
|
||||
|
||||
// Styles are the lipgloss styles derived from a Theme.
|
||||
type Styles struct {
|
||||
Root lipgloss.Style
|
||||
Header lipgloss.Style
|
||||
HeaderTitle lipgloss.Style
|
||||
HeaderMeta lipgloss.Style
|
||||
Info lipgloss.Style
|
||||
Panel lipgloss.Style
|
||||
PanelAlt lipgloss.Style
|
||||
PanelTitle lipgloss.Style
|
||||
ListItem lipgloss.Style
|
||||
ListEnabled lipgloss.Style
|
||||
ListSelected lipgloss.Style
|
||||
Search lipgloss.Style
|
||||
SearchLabel lipgloss.Style
|
||||
SearchInput lipgloss.Style
|
||||
Footer lipgloss.Style
|
||||
Key lipgloss.Style
|
||||
Value lipgloss.Style
|
||||
Text lipgloss.Style
|
||||
Subtle lipgloss.Style
|
||||
Warning lipgloss.Style
|
||||
Empty lipgloss.Style
|
||||
}
|
||||
|
||||
// NormalizeThemeName maps "" and "default" (and anything unknown) to
|
||||
// "slate"; known names stay.
|
||||
func NormalizeThemeName(name string) string {
|
||||
switch name {
|
||||
case "", "default":
|
||||
return "slate"
|
||||
case "slate", "dialog", "midnight":
|
||||
return name
|
||||
default:
|
||||
return "slate"
|
||||
}
|
||||
}
|
||||
|
||||
// NextThemeName is the theme after current in the cycle slate -> dialog ->
|
||||
// midnight -> slate (the F2 key).
|
||||
func NextThemeName(current string) string {
|
||||
switch NormalizeThemeName(current) {
|
||||
case "slate":
|
||||
return "dialog"
|
||||
case "dialog":
|
||||
return "midnight"
|
||||
default:
|
||||
return "slate"
|
||||
}
|
||||
}
|
||||
|
||||
// ThemeByName returns the named theme (see NormalizeThemeName).
|
||||
func ThemeByName(name string) Theme {
|
||||
switch NormalizeThemeName(name) {
|
||||
case "dialog":
|
||||
return Theme{
|
||||
Name: "dialog",
|
||||
Background: lipgloss.Color("#1B2D70"),
|
||||
Panel: lipgloss.Color("#3552A5"),
|
||||
PanelAlt: lipgloss.Color("#2E4A95"),
|
||||
PanelBorder: lipgloss.Color("#AFC6FF"),
|
||||
Text: lipgloss.Color("#F6F8FF"),
|
||||
Muted: lipgloss.Color("#D9E2FF"),
|
||||
Accent: lipgloss.Color("#EDF3FF"),
|
||||
AccentText: lipgloss.Color("#12307A"),
|
||||
Selected: lipgloss.Color("#FFF2A8"),
|
||||
SelectedText: lipgloss.Color("#1B2450"),
|
||||
Success: lipgloss.Color("#C2FFD1"),
|
||||
Warning: lipgloss.Color("#FFE08A"),
|
||||
}
|
||||
case "midnight":
|
||||
return Theme{
|
||||
Name: "midnight",
|
||||
Background: lipgloss.Color("#0B1020"),
|
||||
Panel: lipgloss.Color("#102341"),
|
||||
PanelAlt: lipgloss.Color("#17315A"),
|
||||
PanelBorder: lipgloss.Color("#4C89C8"),
|
||||
Text: lipgloss.Color("#EAF6FF"),
|
||||
Muted: lipgloss.Color("#B6CEE4"),
|
||||
Accent: lipgloss.Color("#FFD166"),
|
||||
AccentText: lipgloss.Color("#12233C"),
|
||||
Selected: lipgloss.Color("#64C7FF"),
|
||||
SelectedText: lipgloss.Color("#0C1D33"),
|
||||
Success: lipgloss.Color("#95E6B0"),
|
||||
Warning: lipgloss.Color("#FFC857"),
|
||||
}
|
||||
default:
|
||||
return Theme{
|
||||
Name: "slate",
|
||||
Background: lipgloss.Color("#1D1F24"),
|
||||
Panel: lipgloss.Color("#2A2A2E"),
|
||||
PanelAlt: lipgloss.Color("#343840"),
|
||||
PanelBorder: lipgloss.Color("#6F7683"),
|
||||
Text: lipgloss.Color("#F2F3F5"),
|
||||
Muted: lipgloss.Color("#C5CAD3"),
|
||||
Accent: lipgloss.Color("#BDC7D8"),
|
||||
AccentText: lipgloss.Color("#1D232F"),
|
||||
Selected: lipgloss.Color("#E7EDF7"),
|
||||
SelectedText: lipgloss.Color("#20242B"),
|
||||
Success: lipgloss.Color("#B5E48C"),
|
||||
Warning: lipgloss.Color("#FFD27D"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Styles derives the lipgloss styles of t.
|
||||
func (t Theme) Styles() Styles {
|
||||
return Styles{
|
||||
Root: lipgloss.NewStyle().
|
||||
Background(t.Background).
|
||||
Foreground(t.Text).
|
||||
Padding(1, 2),
|
||||
Header: lipgloss.NewStyle().
|
||||
Background(t.Accent).
|
||||
Foreground(t.AccentText).
|
||||
Bold(true).
|
||||
Padding(0, 1),
|
||||
HeaderTitle: lipgloss.NewStyle().
|
||||
Background(t.Accent).
|
||||
Foreground(t.AccentText).
|
||||
Bold(true).
|
||||
MarginRight(2),
|
||||
HeaderMeta: lipgloss.NewStyle().
|
||||
Background(t.Accent).
|
||||
Foreground(t.AccentText),
|
||||
Info: lipgloss.NewStyle().
|
||||
Background(t.PanelAlt).
|
||||
Foreground(t.Muted).
|
||||
Padding(0, 1),
|
||||
Panel: lipgloss.NewStyle().
|
||||
Background(t.Panel).
|
||||
Foreground(t.Text).
|
||||
Border(lipgloss.RoundedBorder()).
|
||||
BorderForeground(t.PanelBorder).
|
||||
Padding(1, 1),
|
||||
PanelAlt: lipgloss.NewStyle().
|
||||
Background(t.PanelAlt).
|
||||
Foreground(t.Text).
|
||||
Border(lipgloss.RoundedBorder()).
|
||||
BorderForeground(t.PanelBorder).
|
||||
Padding(1, 1),
|
||||
PanelTitle: lipgloss.NewStyle().
|
||||
Foreground(t.Accent).
|
||||
Bold(true).
|
||||
MarginBottom(1),
|
||||
ListItem: lipgloss.NewStyle().
|
||||
Foreground(t.Text).
|
||||
Padding(0, 1),
|
||||
ListEnabled: lipgloss.NewStyle().
|
||||
Foreground(t.Success).
|
||||
Padding(0, 1),
|
||||
ListSelected: lipgloss.NewStyle().
|
||||
Background(t.Selected).
|
||||
Foreground(t.SelectedText).
|
||||
Bold(true).
|
||||
Padding(0, 1),
|
||||
Search: lipgloss.NewStyle().
|
||||
Background(t.Panel).
|
||||
Foreground(t.Text).
|
||||
Border(lipgloss.NormalBorder()).
|
||||
BorderForeground(t.PanelBorder).
|
||||
Padding(0, 1),
|
||||
SearchLabel: lipgloss.NewStyle().
|
||||
Foreground(t.Accent).
|
||||
Bold(true),
|
||||
SearchInput: lipgloss.NewStyle().
|
||||
Foreground(t.Text),
|
||||
Footer: lipgloss.NewStyle().
|
||||
Background(t.PanelAlt).
|
||||
Foreground(t.Muted).
|
||||
Padding(0, 1),
|
||||
Key: lipgloss.NewStyle().
|
||||
Foreground(t.Accent).
|
||||
Bold(true),
|
||||
Value: lipgloss.NewStyle().
|
||||
Foreground(t.Text),
|
||||
Text: lipgloss.NewStyle().
|
||||
Foreground(t.Text),
|
||||
Subtle: lipgloss.NewStyle().
|
||||
Foreground(t.Muted).
|
||||
Bold(true),
|
||||
Warning: lipgloss.NewStyle().
|
||||
Foreground(t.Warning).
|
||||
Bold(true),
|
||||
Empty: lipgloss.NewStyle().
|
||||
Foreground(t.Muted).
|
||||
Italic(true),
|
||||
}
|
||||
}
|
||||
|
||||
// ThemeNames lists the accepted --theme values.
|
||||
var ThemeNames = []string{"slate", "dialog", "midnight"}
|
||||
|
||||
// ValidTheme reports whether name is one of ThemeNames (or empty).
|
||||
func ValidTheme(name string) bool {
|
||||
if name == "" {
|
||||
return true
|
||||
}
|
||||
for _, n := range ThemeNames {
|
||||
if n == name {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
Reference in new issue
Block a user