all repos — gnotif @ c4fce13a7e58d0326f74ca40dc134fb323ece1e9

A simple dbus monitor to see desktop notifications in the terminal

style.go (view raw)

 1package main
 2
 3import (
 4	"hash/fnv"
 5
 6	"github.com/charmbracelet/lipgloss"
 7
 8	catppuccin "github.com/catppuccin/go"
 9)
10
11var Catppuccin catppuccin.Flavor = catppuccin.Mocha
12
13var catppuccinColors []string = []string{
14	Catppuccin.Red().Hex,
15	Catppuccin.Green().Hex,
16	Catppuccin.Yellow().Hex,
17	Catppuccin.Blue().Hex,
18	Catppuccin.Mauve().Hex,
19	Catppuccin.Pink().Hex,
20	Catppuccin.Flamingo().Hex,
21	Catppuccin.Teal().Hex,
22	Catppuccin.Sky().Hex,
23	Catppuccin.Sapphire().Hex,
24	Catppuccin.Maroon().Hex,
25	Catppuccin.Peach().Hex,
26	Catppuccin.Rosewater().Hex,
27	Catppuccin.Lavender().Hex,
28}
29
30var datetimeStyle = lipgloss.NewStyle().Foreground(lipgloss.Color(Catppuccin.Subtext0().Hex))
31var summaryStyle = lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color(Catppuccin.Lavender().Hex))
32var bodyStyle = lipgloss.NewStyle().Foreground(lipgloss.Color(Catppuccin.Text().Hex))
33
34func getAppNameStyle(appName string) lipgloss.Style {
35	color := deterministicRandomString(appName, catppuccinColors)
36	return lipgloss.NewStyle().Background(lipgloss.Color(color)).Foreground(lipgloss.Color(Catppuccin.Base().Hex)).Padding(0, 1)
37}
38
39func deterministicRandomString(key string, array []string) string {
40	hasher := fnv.New32a()
41	hasher.Write([]byte(key))
42	hashValue := hasher.Sum32()
43
44	index := int(hashValue) % len(array)
45	return array[index]
46}