This commit is contained in:
katistix committed 2026-10-09 18:50:53 +03:00
1 parent cb0b0f6fb0
commit 914ddd7d12
11 files changed
+833 -33

No files matched your search

+41 -24
View File
@@ -1,22 +1,18 @@
// Package ui contains the bubbletea model and lipgloss styles.
// Package ui contains the bubbletea models and lipgloss styles.
package ui
import (
"strings"
"github.com/charmbracelet/lipgloss"
"github.com/katistix/termitype/internal/theme"
)
var (
// Palette: muted background, monkeytype-ish yellow accent.
accent = lipgloss.Color("#e2b714")
muted = lipgloss.Color("#646669")
fg = lipgloss.Color("#d1d0c5")
bad = lipgloss.Color("#ca4754")
bg = lipgloss.Color("#323437")
cursorBg = lipgloss.Color("#e2b714")
cursorFg = lipgloss.Color("#323437")
)
// Styles are built from a theme. Every style sets the theme background:
// ANSI resets between styled segments would otherwise punch holes in it.
type Styles struct {
Bg lipgloss.Color
Base lipgloss.Style // plain text and gaps on the theme background
App lipgloss.Style
Title lipgloss.Style
Hint lipgloss.Style
@@ -30,18 +26,39 @@ type Styles struct {
StatVal lipgloss.Style
}
func DefaultStyles() Styles {
func NewStyles(t theme.Theme) Styles {
bg := lipgloss.Color(t.Bg)
base := lipgloss.NewStyle().Background(bg)
fg := func(c string) lipgloss.Style { return base.Foreground(lipgloss.Color(c)) }
return Styles{
App: lipgloss.NewStyle().Padding(1, 2),
Title: lipgloss.NewStyle().Bold(true).Foreground(accent),
Hint: lipgloss.NewStyle().Foreground(muted),
Box: lipgloss.NewStyle().Padding(1, 2).Border(lipgloss.RoundedBorder()).BorderForeground(bg),
Pending: lipgloss.NewStyle().Foreground(muted),
Correct: lipgloss.NewStyle().Foreground(fg),
Wrong: lipgloss.NewStyle().Foreground(bad),
Extra: lipgloss.NewStyle().Foreground(bad).Background(lipgloss.Color("#4a2b2e")),
Cursor: lipgloss.NewStyle().Background(cursorBg).Foreground(cursorFg),
Stat: lipgloss.NewStyle().Foreground(muted),
StatVal: lipgloss.NewStyle().Bold(true).Foreground(accent),
Bg: bg,
Base: base,
App: base.Padding(1, 2),
Title: fg(t.Main).Bold(true),
Hint: fg(t.Sub),
Box: base.Padding(1, 2).Border(lipgloss.RoundedBorder()).BorderForeground(lipgloss.Color(t.SubAlt)).BorderBackground(bg),
Pending: fg(t.Sub),
Correct: fg(t.Text),
Wrong: fg(t.Error),
Extra: fg(t.ErrorExtra),
Cursor: lipgloss.NewStyle().Background(lipgloss.Color(t.Caret)).Foreground(bg),
Stat: fg(t.Sub),
StatVal: fg(t.Main).Bold(true),
}
}
// fill paints content over the whole terminal in the theme background.
func (s Styles) fill(content string, width, height int) string {
if width <= 0 || height <= 0 {
return content
}
// Joins and padding emit plain spaces after a style reset; re-apply
// the background after each reset and at each line start.
bgSeq, _, _ := strings.Cut(s.Base.Render("x"), "x")
if bgSeq != "" {
content = strings.ReplaceAll(content, "\x1b[0m", "\x1b[0m"+bgSeq)
content = bgSeq + strings.ReplaceAll(content, "\n", "\n"+bgSeq)
}
return lipgloss.Place(width, height, lipgloss.Left, lipgloss.Top, content,
lipgloss.WithWhitespaceBackground(s.Bg))
}