Skip to content

Commit

Permalink
feat: add adaptative colors for both light and dark terminals
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiolaverde0 committed Mar 28, 2024
1 parent f068ace commit 803f7ce
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 22 deletions.
10 changes: 5 additions & 5 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ func Execute() {
// colored cobra injection
cc.Init(&cc.Config{
RootCmd: rootCmd,
Headings: cc.HiCyan + cc.Bold + cc.Underline,
Commands: cc.HiYellow + cc.Bold,
Headings: cc.Cyan + cc.Bold + cc.Underline,
Commands: cc.Yellow + cc.Bold,
Example: cc.Italic,
ExecName: cc.Bold,
Flags: cc.Bold,
FlagsDataType: cc.Italic + cc.HiBlue,
ExecName: cc.Green + cc.Bold,
Flags: cc.Green + cc.Bold,
FlagsDataType: cc.Italic + cc.Blue,
})
}

Expand Down
25 changes: 12 additions & 13 deletions color/color.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@ package color
import "github.com/charmbracelet/lipgloss"

var (
Red = New("1")
Green = New("2")
Yellow = New("3")
Blue = New("4")
Purple = New("5")
Cyan = New("6")
HiBg = New("7")
HiFg = New("10")
Fg = New("11")
Bg = New("15")
Red = lipgloss.Color("1")
Green = lipgloss.Color("2")
Yellow = lipgloss.Color("3")
Blue = lipgloss.Color("4")
Purple = lipgloss.Color("5")
Cyan = lipgloss.Color("6")
)

func New(color string) lipgloss.Color {
return lipgloss.Color(color)
}
var (
HiBg = lipgloss.AdaptiveColor{Light: "7", Dark: "0"}
HiFg = lipgloss.AdaptiveColor{Light: "10", Dark: "14"}
Fg = lipgloss.AdaptiveColor{Light: "11", Dark: "12"}
Bg = lipgloss.AdaptiveColor{Light: "15", Dark: "8"}
)
6 changes: 3 additions & 3 deletions style/style.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ func New() lipgloss.Style {
return lipgloss.NewStyle()
}

func NewColored(foreground, background lipgloss.Color) lipgloss.Style {
func NewColored(foreground, background lipgloss.TerminalColor) lipgloss.Style {
return New().Foreground(foreground).Background(background)
}

func Fg(color lipgloss.Color) func(string) string {
return NewColored(color, "").Render
return NewColored(color, lipgloss.NoColor{}).Render
}

func Bg(color lipgloss.Color) func(string) string {
return NewColored("", color).Render
return NewColored(lipgloss.NoColor{}, color).Render
}

func Truncate(max int) func(string) string {
Expand Down
2 changes: 1 addition & 1 deletion tui/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (b *statefulBubble) viewSearch() string {
"",
fmt.Sprintf("Search %s ?", style.Fg(color.Yellow)(b.searchSuggestion.MustGet())),
"",
fmt.Sprintf("Press %s to accept", style.Bold(style.Faint(b.keymap.acceptSearchSuggestion.Help().Key))),
fmt.Sprintf("Press %s to accept", style.Bold(b.keymap.acceptSearchSuggestion.Help().Key)),
)
}

Expand Down

0 comments on commit 803f7ce

Please sign in to comment.