Skip to content

Commit edb2bfa

Browse files
defining new styles and theme for speed command (#166)
1 parent 48c5770 commit edb2bfa

File tree

1 file changed

+55
-5
lines changed

1 file changed

+55
-5
lines changed

styling/styling.go

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@ package styling
22

33
import (
44
"fmt"
5+
"github.com/charmbracelet/huh"
56
"github.com/charmbracelet/lipgloss"
67
"image/color"
78
"regexp"
89
)
910

1011
var (
11-
Green = lipgloss.NewStyle().Foreground(lipgloss.Color("#38B000"))
12-
Red = lipgloss.NewStyle().Foreground(lipgloss.Color("#D00000"))
13-
Gray = lipgloss.Color("#777777")
12+
Green = lipgloss.NewStyle().Foreground(lipgloss.Color("#38B000"))
13+
Red = lipgloss.NewStyle().Foreground(lipgloss.Color("#D00000"))
14+
Gray = lipgloss.Color("#777777")
15+
YellowAdaptive = func(s string) string {
16+
return lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "#E1AD01", Dark: "#FFDE00"}).Render(s)
17+
}
1418
ColoredBullet = lipgloss.NewStyle().
1519
SetString("•").
1620
Foreground(lipgloss.Color("#FFCC00"))
@@ -69,15 +73,15 @@ func StripANSI(input string) string {
6973
return ansiRegex.ReplaceAllString(input, "")
7074
}
7175

72-
// To avoid unnecessary dependencies, I adapted the MakeColor function from
76+
// Color To avoid unnecessary dependencies, I adapted the MakeColor function from
7377
// "github.com/lucasb-eyer/go-colorful" and implemented it using only the
7478
// standard library. Since I only needed this function, importing the entire
7579
// library was unnecessary.
7680
type Color struct {
7781
R, G, B float64
7882
}
7983

80-
// Implement the Go color.Color interface.
84+
// RGBA Implement the Go color.Color interface.
8185
func (col Color) RGBA() (uint32, uint32, uint32, uint32) {
8286
return uint32(col.R*65535.0 + 0.5), uint32(col.G*65535.0 + 0.5), uint32(col.B*65535.0 + 0.5), 0xFFFF
8387
}
@@ -102,3 +106,49 @@ func (col Color) Hex() string {
102106
return fmt.Sprintf("#%02x%02x%02x",
103107
uint8(col.R*255.0+0.5), uint8(col.G*255.0+0.5), uint8(col.B*255.0+0.5))
104108
}
109+
110+
func FormTheme() *huh.Theme {
111+
var (
112+
yellow = lipgloss.Color("#FFDE00")
113+
blue = lipgloss.Color("#3B4CCA")
114+
red = lipgloss.Color("#D00000")
115+
black = lipgloss.Color("#000000")
116+
normalFg = lipgloss.AdaptiveColor{Light: "235", Dark: "252"}
117+
)
118+
t := huh.ThemeBase()
119+
120+
t.Focused.Base = t.Focused.Base.BorderForeground(lipgloss.Color("238"))
121+
t.Focused.Card = t.Focused.Base
122+
t.Focused.Title = t.Focused.Title.Foreground(blue).Bold(true)
123+
t.Focused.NoteTitle = t.Focused.NoteTitle.Foreground(blue).Bold(true).MarginBottom(1)
124+
t.Focused.Directory = t.Focused.Directory.Foreground(blue)
125+
t.Focused.Description = t.Focused.Description.Foreground(lipgloss.AdaptiveColor{Light: "", Dark: "243"})
126+
t.Focused.ErrorIndicator = t.Focused.ErrorIndicator.Foreground(red)
127+
t.Focused.ErrorMessage = t.Focused.ErrorMessage.Foreground(red)
128+
t.Focused.SelectSelector = t.Focused.SelectSelector.Foreground(red)
129+
t.Focused.NextIndicator = t.Focused.NextIndicator.Foreground(yellow)
130+
t.Focused.PrevIndicator = t.Focused.PrevIndicator.Foreground(yellow)
131+
t.Focused.Option = t.Focused.Option.Foreground(normalFg)
132+
t.Focused.MultiSelectSelector = t.Focused.MultiSelectSelector.Foreground(red)
133+
t.Focused.SelectedOption = t.Focused.SelectedOption.Foreground(red)
134+
t.Focused.SelectedPrefix = lipgloss.NewStyle().Foreground(red).SetString("✓ ")
135+
t.Focused.UnselectedPrefix = lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "", Dark: "243"}).SetString("• ")
136+
t.Focused.UnselectedOption = t.Focused.UnselectedOption.Foreground(normalFg)
137+
t.Focused.FocusedButton = t.Focused.FocusedButton.Foreground(black).Background(yellow)
138+
t.Focused.Next = t.Focused.FocusedButton
139+
140+
t.Focused.TextInput.Cursor = t.Focused.TextInput.Cursor.Foreground(yellow)
141+
t.Focused.TextInput.Placeholder = t.Focused.TextInput.Placeholder.Foreground(lipgloss.AdaptiveColor{Light: "248", Dark: "238"})
142+
t.Focused.TextInput.Prompt = t.Focused.TextInput.Prompt.Foreground(red)
143+
144+
t.Blurred = t.Focused
145+
t.Blurred.Base = t.Focused.Base.BorderStyle(lipgloss.HiddenBorder())
146+
t.Blurred.Card = t.Blurred.Base
147+
t.Blurred.NextIndicator = lipgloss.NewStyle()
148+
t.Blurred.PrevIndicator = lipgloss.NewStyle()
149+
150+
t.Group.Title = t.Focused.Title
151+
t.Group.Description = t.Focused.Description
152+
153+
return t
154+
}

0 commit comments

Comments
 (0)