mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: use ANSI colors codes instead of RGB (#14665)
* chore: add command for showing colors * fix: use ANSI color codes instead of RGB * feat: add '--no-color' flag * fix: revert colors * chore: change colors * fix: update golden files * fix: replace blue with brightBlue * fix: drop '> ' for unfocused prompts * fix: run 'make fmt' * chore: allow disabling color with env flags * fix: apply fixes from feedback * fix: run 'make gen' * fix: refactor janky code * fix: re-add public function * fix: re-add init for non-color tests * fix: move styles to 'init' that can be * fix: stop overwriting entire DefaultStyles * fix: make code and field obey --no-color * fix: rip out '--no-color' due to race condition We still support `NO_COLOR` env variable through termenv's `EnvColorProfile`. The reason for the race condition is that `DefaultStyles` is a global that we shouldn't mutate after `init` is called, but we have to mutate it after `init` has ran to have serpent collect the cli flags and env vars for us. * fix: apply nit * fix: simplify code && hide command * fix: newline shouldn't be themed * fix: appease the linter
This commit is contained in:
+29
-22
@@ -37,17 +37,21 @@ var (
|
||||
)
|
||||
|
||||
var (
|
||||
Green = Color("#04B575")
|
||||
Red = Color("#ED567A")
|
||||
Fuchsia = Color("#EE6FF8")
|
||||
Yellow = Color("#ECFD65")
|
||||
Blue = Color("#5000ff")
|
||||
// ANSI color codes
|
||||
red = Color("1")
|
||||
green = Color("2")
|
||||
yellow = Color("3")
|
||||
magenta = Color("5")
|
||||
white = Color("7")
|
||||
brightBlue = Color("12")
|
||||
brightMagenta = Color("13")
|
||||
)
|
||||
|
||||
// Color returns a color for the given string.
|
||||
func Color(s string) termenv.Color {
|
||||
colorOnce.Do(func() {
|
||||
color = termenv.NewOutput(os.Stdout).ColorProfile()
|
||||
color = termenv.NewOutput(os.Stdout).EnvColorProfile()
|
||||
|
||||
if flag.Lookup("test.v") != nil {
|
||||
// Use a consistent colorless profile in tests so that results
|
||||
// are deterministic.
|
||||
@@ -123,42 +127,45 @@ func init() {
|
||||
DefaultStyles = Styles{
|
||||
Code: pretty.Style{
|
||||
ifTerm(pretty.XPad(1, 1)),
|
||||
pretty.FgColor(Red),
|
||||
pretty.BgColor(color.Color("#2c2c2c")),
|
||||
pretty.FgColor(Color("#ED567A")),
|
||||
pretty.BgColor(Color("#2C2C2C")),
|
||||
},
|
||||
DateTimeStamp: pretty.Style{
|
||||
pretty.FgColor(color.Color("#7571F9")),
|
||||
pretty.FgColor(brightBlue),
|
||||
},
|
||||
Error: pretty.Style{
|
||||
pretty.FgColor(Red),
|
||||
pretty.FgColor(red),
|
||||
},
|
||||
Field: pretty.Style{
|
||||
pretty.XPad(1, 1),
|
||||
pretty.FgColor(color.Color("#FFFFFF")),
|
||||
pretty.BgColor(color.Color("#2b2a2a")),
|
||||
pretty.FgColor(Color("#FFFFFF")),
|
||||
pretty.BgColor(Color("#2B2A2A")),
|
||||
},
|
||||
Fuchsia: pretty.Style{
|
||||
pretty.FgColor(brightMagenta),
|
||||
},
|
||||
FocusedPrompt: pretty.Style{
|
||||
pretty.FgColor(white),
|
||||
pretty.Wrap("> ", ""),
|
||||
pretty.FgColor(brightBlue),
|
||||
},
|
||||
Keyword: pretty.Style{
|
||||
pretty.FgColor(Green),
|
||||
pretty.FgColor(green),
|
||||
},
|
||||
Placeholder: pretty.Style{
|
||||
pretty.FgColor(color.Color("#4d46b3")),
|
||||
pretty.FgColor(magenta),
|
||||
},
|
||||
Prompt: pretty.Style{
|
||||
pretty.FgColor(color.Color("#5C5C5C")),
|
||||
pretty.Wrap("> ", ""),
|
||||
pretty.FgColor(white),
|
||||
pretty.Wrap(" ", ""),
|
||||
},
|
||||
Warn: pretty.Style{
|
||||
pretty.FgColor(Yellow),
|
||||
pretty.FgColor(yellow),
|
||||
},
|
||||
Wrap: pretty.Style{
|
||||
pretty.LineWrap(80),
|
||||
},
|
||||
}
|
||||
|
||||
DefaultStyles.FocusedPrompt = append(
|
||||
DefaultStyles.Prompt,
|
||||
pretty.FgColor(Blue),
|
||||
)
|
||||
}
|
||||
|
||||
// ValidateNotEmpty is a helper function to disallow empty inputs!
|
||||
|
||||
Reference in New Issue
Block a user