126 lines
3.4 KiB
Go
126 lines
3.4 KiB
Go
package main
|
||
|
||
// One palette, two variants, named by role.
|
||
//
|
||
// Catppuccin, because it is the scheme people already run in this terminal and
|
||
// because its two variants are designed together: the same roles keep the same
|
||
// meaning in light and dark. Panels ask for a role and never for a colour, so a
|
||
// light terminal needs no second design.
|
||
|
||
import (
|
||
"os"
|
||
"strings"
|
||
)
|
||
|
||
type palette struct {
|
||
Base string
|
||
Surface string
|
||
Overlay string
|
||
Text string
|
||
Muted string
|
||
Accent string
|
||
Info string
|
||
Success string
|
||
Warning string
|
||
Error string
|
||
Mauve string
|
||
Selection string
|
||
}
|
||
|
||
var mocha = palette{
|
||
Base: "#1e1e2e",
|
||
Surface: "#313244",
|
||
Overlay: "#6c7086",
|
||
Text: "#cdd6f4",
|
||
Muted: "#a6adc8",
|
||
Accent: "#89b4fa",
|
||
Info: "#94e2d5",
|
||
Success: "#a6e3a1",
|
||
Warning: "#f9e2af",
|
||
Error: "#f38ba8",
|
||
Mauve: "#cba6f7",
|
||
Selection: "#45475a",
|
||
}
|
||
|
||
var latte = palette{
|
||
Base: "#eff1f5",
|
||
Surface: "#ccd0da",
|
||
Overlay: "#8c8fa1",
|
||
Text: "#4c4f69",
|
||
Muted: "#6c6f85",
|
||
Accent: "#1e66f5",
|
||
Info: "#179299",
|
||
Success: "#40a02b",
|
||
Warning: "#df8e1d",
|
||
Error: "#d20f39",
|
||
Mauve: "#8839ef",
|
||
Selection: "#bcc0cc",
|
||
}
|
||
|
||
// active is the palette this run draws with. It is chosen once, at startup, so
|
||
// nothing downstream has to think about it.
|
||
var active = mocha
|
||
|
||
func choosePalette(force string) {
|
||
switch strings.ToLower(force) {
|
||
case "light":
|
||
active = latte
|
||
case "dark":
|
||
active = mocha
|
||
default:
|
||
// COLORFGBG is what many terminals export: "foreground;background".
|
||
if v := os.Getenv("COLORFGBG"); v != "" {
|
||
parts := strings.Split(v, ";")
|
||
bg := parts[len(parts)-1]
|
||
// A light background is one of the high numbers in the 16-colour
|
||
// range; anything above 6 is light in practice.
|
||
if bg == "15" || bg == "7" {
|
||
active = latte
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
// Icons. Nerd Font glyphs, with an ASCII fallback so the interface still reads
|
||
// when the font is not installed or the terminal cannot show it: -ascii, or a
|
||
// TERM that says it cannot, chooses the fallback.
|
||
type glyphSet struct {
|
||
Todo, Running, Blocked, Review, Done, Cancelled string
|
||
Folder, Branch, Commit, Cost, Person, Agent string
|
||
Arrow, Dot, Rule string
|
||
}
|
||
|
||
var nerdGlyphs = glyphSet{
|
||
Todo: "\uf10c", Running: "\uf04b", Blocked: "\uf05e", Review: "\uf06e",
|
||
Done: "\uf00c", Cancelled: "\uf00d",
|
||
Folder: "\uf07b", Branch: "\uf126", Commit: "\uf1d3", Cost: "\uf155",
|
||
Person: "\uf007", Agent: "\uf085",
|
||
Arrow: "\uf105", Dot: "\uf111", Rule: "─",
|
||
}
|
||
|
||
var plainGlyphs = glyphSet{
|
||
Todo: "·", Running: "▶", Blocked: "■", Review: "◆",
|
||
Done: "✓", Cancelled: "✕",
|
||
Folder: "/", Branch: "branch", Commit: "commit", Cost: "cents",
|
||
Person: "you", Agent: "agent",
|
||
Arrow: "›", Dot: "·", Rule: "─",
|
||
}
|
||
|
||
// icons starts as plain Unicode on purpose. The Nerd Font is installed, but a
|
||
// private-use glyph does not survive TUIOS's own screen capture, so whether it
|
||
// draws cannot be checked from here. The words next to every icon carry the
|
||
// meaning either way, and -nerd opts into the richer set once it has been seen
|
||
// on the terminal that matters.
|
||
// The Nerd Font is installed, so the icons are on by default; -ascii switches
|
||
// to plain characters for a terminal that cannot draw them. Either way the word
|
||
// next to the icon carries the meaning.
|
||
var icons = nerdGlyphs
|
||
|
||
func chooseGlyphs(useASCII bool) {
|
||
if useASCII {
|
||
icons = plainGlyphs
|
||
return
|
||
}
|
||
icons = nerdGlyphs
|
||
}
|