feat(theme): add catppuccin themes with transparency and 256-color support
Add a theme package providing all four catppuccin flavors (mocha, frappe, macchiato, latte) mapped to the xterm-256 palette. Themes are selected with -theme or the CTOP_THEME environment variable; -i inverts the flavor. Background slots use the terminal's native color for transparency (opt out with -solid / CTOP_SOLID), and termbox is switched to Output256 so colors render correctly. Replace hardcoded colors in the compact and single views with ctheme portrait slots.
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/bcicen/ctop/container"
|
||||
"github.com/bcicen/ctop/cwidgets/compact"
|
||||
"github.com/bcicen/ctop/logging"
|
||||
"github.com/bcicen/ctop/theme"
|
||||
"github.com/bcicen/ctop/widgets"
|
||||
ui "github.com/gizak/termui"
|
||||
tm "github.com/nsf/termbox-go"
|
||||
@@ -45,6 +46,8 @@ func main() {
|
||||
reverseSortFlag = flag.Bool("r", false, "reverse container sort order")
|
||||
invertFlag = flag.Bool("i", false, "invert default colors")
|
||||
connectorFlag = flag.String("connector", "docker", "container connector to use")
|
||||
themeFlag = flag.String("theme", "", "catppuccin color theme (mocha, frappe, macchiato, latte)")
|
||||
solidFlag = flag.Bool("solid", false, "paint opaque catppuccin background instead of transparent")
|
||||
)
|
||||
flag.Parse()
|
||||
|
||||
@@ -85,15 +88,39 @@ func main() {
|
||||
config.Toggle("sortReversed")
|
||||
}
|
||||
|
||||
// resolve catppuccin theme in order: -theme flag, CTOP_THEME env, default
|
||||
themeName := "mocha"
|
||||
switch {
|
||||
case *themeFlag != "":
|
||||
themeName = *themeFlag
|
||||
case os.Getenv("CTOP_THEME") != "":
|
||||
themeName = os.Getenv("CTOP_THEME")
|
||||
}
|
||||
flavor, ok := theme.ParseFlavor(themeName)
|
||||
if !ok {
|
||||
fmt.Printf("invalid theme: %q (available: %s)\n", themeName, strings.Join(theme.Flavors(), ", "))
|
||||
os.Exit(1)
|
||||
}
|
||||
theme.Set(flavor)
|
||||
solid := *solidFlag
|
||||
switch os.Getenv("CTOP_SOLID") {
|
||||
case "1", "true", "TRUE", "yes", "YES":
|
||||
solid = true
|
||||
}
|
||||
theme.SetOpaque(solid)
|
||||
|
||||
// init ui
|
||||
if *invertFlag {
|
||||
InvertColorMap()
|
||||
} else {
|
||||
SetColorMap()
|
||||
}
|
||||
ui.ColorMap = ColorMap // override default colormap
|
||||
if err := ui.Init(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
tm.SetInputMode(tm.InputAlt)
|
||||
tm.SetOutputMode(tm.Output256) // enable 256-color catppuccin palette
|
||||
|
||||
defer Shutdown()
|
||||
// init grid, cursor, header
|
||||
@@ -150,6 +177,8 @@ options:
|
||||
func printHelp() {
|
||||
fmt.Println(helpMsg)
|
||||
flag.PrintDefaults()
|
||||
fmt.Printf("\ncatppuccin themes: mocha (default), frappe, macchiato, latte\n")
|
||||
fmt.Printf("select a theme with -theme or the CTOP_THEME environment variable\n")
|
||||
fmt.Printf("\navailable connectors: ")
|
||||
fmt.Println(strings.Join(connector.Enabled(), ", "))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user