summaryrefslogtreecommitdiff
path: root/internal/ui/style.go
blob: bab94ca06b0d3f6628a5262b4486ae39652b3fd9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package ui

import (
	"github.com/ChausseBenjamin/termpicker/internal/progress"
	lg "github.com/charmbracelet/lipgloss"
)

const (
	textSel   = "#F2F1F0"
	textNorm  = "#A7AFB1"
	textFaint = "#6F797B"
	geomFg    = "#ACB3B5"
	textWarn  = "#EA9139"

	TabSepLeft  = "["
	TabSepMid   = " | "
	TabSepRight = "]"

	PickerSelRune = ">"

	PromptPrefix      = "> "
	PromptPlaceholder = "Enter a color (ex: #b7416e)"

	SliderMinWidth = 22 // 1 ASCII change every 2.05 deg. avg
	SliderMaxWidth = 90 // 2 ASCII change per deg.

	BoxOffsetW, BoxOffsetH = 2, 2
)

type sliderOpts struct {
	R, G, B    []progress.Option
	C, M, Y, K []progress.Option
	H, S, L    []progress.Option
}

type StyleSheet struct {
	TabSel       lg.Style
	TabNorm      lg.Style
	TabGeom      lg.Style
	SliderVal    lg.Style
	SliderLabel  lg.Style
	PickerCursor lg.Style
	Preview      lg.Style
	InputPrompt  lg.Style
	InputText    lg.Style
	Notice       lg.Style
	TooSmall     lg.Style
	Quit         lg.Style
	Boxed        lg.Style
	Sliders      sliderOpts
}

var style StyleSheet

func Style() StyleSheet {
	return style
}

func init() {
	baseStyle := lg.NewStyle().
		Foreground(lg.Color(textNorm))

	baseSliderOpts := []progress.Option{
		progress.WithColorProfile(ColorProfile()),
		progress.WithoutPercentage(),
		// progress.WithBinaryFill(), // uncomment for legacy look
	}

	style = StyleSheet{
		TabSel: baseStyle.Inherit(lg.NewStyle().
			Underline(true).
			Bold(true)).
			Foreground(lg.Color(textSel)),

		TabNorm: baseStyle.Inherit(lg.NewStyle().
			Underline(false).
			Faint(true).
			Bold(false)).
			Foreground(lg.Color(textFaint)),

		TabGeom: baseStyle.Inherit(lg.NewStyle().
			Foreground(lg.Color(geomFg))),

		SliderVal: baseStyle,

		SliderLabel: baseStyle,

		PickerCursor: baseStyle.Inherit(lg.NewStyle().
			Bold(true)),

		Preview: baseStyle,

		InputPrompt: baseStyle.Inherit(lg.NewStyle().
			Bold(true)),

		InputText: baseStyle,

		Notice: baseStyle.Inherit(lg.NewStyle().
			Bold(true)),

		TooSmall: baseStyle.Inherit(lg.NewStyle().
			Bold(true)).
			Blink(true).
			Foreground(lg.Color(textWarn)),

		Quit: baseStyle.Inherit(lg.NewStyle().
			Bold(true)).
			Foreground(lg.Color(textSel)),

		Boxed: baseStyle.Inherit(lg.NewStyle().
			Border(lg.RoundedBorder())),

		Sliders: sliderOpts{
			// RGB
			R: append(baseSliderOpts, progress.WithGradient("#660000", "#ff0000")),
			G: append(baseSliderOpts, progress.WithGradient("#006600", "#00ff00")),
			B: append(baseSliderOpts, progress.WithGradient("#000066", "#0000ff")),

			// CMYK
			C: append(baseSliderOpts, progress.WithGradient("#006666", "#00ffff")),
			M: append(baseSliderOpts, progress.WithGradient("#660066", "#ff00ff")),
			Y: append(baseSliderOpts, progress.WithGradient("#666600", "#ffff00")),
			K: append(baseSliderOpts, progress.WithSolidFill("#000000")),

			// HSL
			H: append(baseSliderOpts, progress.WithDefaultGradient()),
			S: append(baseSliderOpts, progress.WithGradient("#a68e59", "#ffae00")),
			L: append(baseSliderOpts, progress.WithGradient("#222222", "#ffffff")),
		},
	}
}