Skip to content

Commit e286475

Browse files
committed
♻️Simplify use of ascii colors
1 parent a1eb7be commit e286475

File tree

1 file changed

+15
-30
lines changed

1 file changed

+15
-30
lines changed

main.go

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,54 +13,39 @@ import (
1313

1414
"github.com/charmbracelet/fang"
1515
"github.com/charmbracelet/lipgloss/v2"
16+
"github.com/charmbracelet/x/term"
1617
"github.com/joshmedeski/sesh/v2/seshcli"
1718
)
1819

1920
var version = "dev"
2021

21-
var (
22-
Black = lipgloss.Color("0")
23-
Red = lipgloss.Color("1")
24-
Green = lipgloss.Color("2")
25-
Yellow = lipgloss.Color("3")
26-
Blue = lipgloss.Color("4")
27-
Magenta = lipgloss.Color("5")
28-
Cyan = lipgloss.Color("6")
29-
White = lipgloss.Color("7")
30-
BrightBlack = lipgloss.Color("8")
31-
BrightRed = lipgloss.Color("9")
32-
BrightGreen = lipgloss.Color("10")
33-
BrightYellow = lipgloss.Color("11")
34-
BrightBlue = lipgloss.Color("12")
35-
BrightMagenta = lipgloss.Color("13")
36-
BrightCyan = lipgloss.Color("14")
37-
BrightWhite = lipgloss.Color("15")
38-
)
39-
4022
func AnsiTheme() fang.ColorScheme {
41-
isDark := lipgloss.HasDarkBackground(os.Stdin, os.Stderr)
23+
var isDark bool
24+
if term.IsTerminal(os.Stdout.Fd()) {
25+
isDark = lipgloss.HasDarkBackground(os.Stdin, os.Stderr)
26+
}
4227
c := lipgloss.LightDark(isDark)
43-
base := c(Black, White)
44-
inverted := c(White, Black)
45-
muted := c(BrightBlack, BrightWhite)
28+
base := c(lipgloss.Black, lipgloss.White)
29+
inverted := c(lipgloss.White, lipgloss.Black)
30+
muted := c(lipgloss.BrightBlack, lipgloss.BrightWhite)
4631

4732
return fang.ColorScheme{
4833
Base: base,
49-
Title: Blue,
34+
Title: lipgloss.Blue,
5035
Description: base,
5136
Codeblock: base,
5237
Program: inverted,
5338
DimmedArgument: inverted,
5439
Comment: muted,
55-
Flag: Magenta,
56-
FlagDefault: BrightMagenta,
57-
Command: Cyan,
58-
QuotedString: Green,
40+
Flag: lipgloss.Magenta,
41+
FlagDefault: lipgloss.BrightMagenta,
42+
Command: lipgloss.Cyan,
43+
QuotedString: lipgloss.Green,
5944
Argument: base,
6045
Help: base,
6146
Dash: base,
62-
ErrorHeader: [2]color.Color{Black, Red},
63-
ErrorDetails: Red,
47+
ErrorHeader: [2]color.Color{lipgloss.Black, lipgloss.Red},
48+
ErrorDetails: lipgloss.Red,
6449
}
6550
}
6651

0 commit comments

Comments
 (0)