4a579bdbc6
CI / test (pull_request) Successful in 4s
Every colour was a 256-colour ANSI index hardcoded in styles.go, so changing the palette meant editing the styles themselves. This puts a semantic token set between the two: styles name roles, a theme supplies the colours. internal/theme holds the twelve tokens, the two built-ins (gruvbox-dark, the new default, and gruvbox-light) and the loader for user themes in ~/.config/terdut-tui/themes/. A user file may 'extends:' a built-in and override only what it cares about, and may shadow a built-in name to tweak it in place. Unknown keys, malformed colours and incomplete themes are refused with a message naming what went wrong. Colours are truecolor hex now: lipgloss downsamples for 256- and 16-colour terminals and honours NO_COLOR, so themes carry no fallbacks of their own. An ANSI index is still accepted for anyone who would rather follow their terminal's own palette. The 21 package-level style vars become a Styles struct on the Model, which is what rule 3 asked for all along; the four free functions in view.go take one as their first argument. The embedded bubbles components are restyled from the same tokens — otherwise a theme would leave a pink selected row and grey help text behind. Note that the table's Cell style deliberately keeps no foreground: bubbles renders cells before wrapping the row in Selected, so a colour there cuts the selection highlight short.
57 lines
1.2 KiB
Go
57 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"os"
|
|
|
|
"git.ryuvia.com/niklas/terdut-tui/internal/api"
|
|
"git.ryuvia.com/niklas/terdut-tui/internal/config"
|
|
"git.ryuvia.com/niklas/terdut-tui/internal/theme"
|
|
"git.ryuvia.com/niklas/terdut-tui/internal/tui"
|
|
"git.ryuvia.com/niklas/terdut-tui/internal/updater"
|
|
tea "github.com/charmbracelet/bubbletea"
|
|
)
|
|
|
|
var version = "dev"
|
|
|
|
func main() {
|
|
versionFlag := flag.Bool("version", false, "print version and exit")
|
|
updateFlag := flag.Bool("self-update", false, "update terdut-tui to the latest release")
|
|
flag.Parse()
|
|
|
|
if *versionFlag {
|
|
fmt.Println(version)
|
|
os.Exit(0)
|
|
}
|
|
|
|
if *updateFlag {
|
|
if err := updater.Run(version); err != nil {
|
|
fmt.Fprintln(os.Stderr, "update:", err)
|
|
os.Exit(1)
|
|
}
|
|
os.Exit(0)
|
|
}
|
|
|
|
cfg, err := config.Load()
|
|
if err != nil {
|
|
fmt.Fprintln(os.Stderr, err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
th, err := theme.Load(cfg.Theme)
|
|
if err != nil {
|
|
fmt.Fprintln(os.Stderr, err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
client := api.NewClient(cfg.ServerURL, cfg.APIKey)
|
|
model := tui.NewModel(client, cfg.ServerURL, cfg.RefreshInterval, th)
|
|
|
|
p := tea.NewProgram(model, tea.WithAltScreen())
|
|
if _, err := p.Run(); err != nil {
|
|
fmt.Fprintln(os.Stderr, "error:", err)
|
|
os.Exit(1)
|
|
}
|
|
}
|