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:
Danielle Maywood
2024-09-17 14:21:24 +01:00
committed by GitHub
parent 6ff9a05832
commit 14d3e300d3
3 changed files with 73 additions and 27 deletions

View File

@ -18,6 +18,7 @@ import (
"github.com/coder/coder/v2/cli/cliui"
"github.com/coder/coder/v2/coderd/database/dbtime"
"github.com/coder/coder/v2/codersdk"
"github.com/coder/pretty"
"github.com/coder/serpent"
)
@ -37,6 +38,44 @@ func main() {
},
}
root.Children = append(root.Children, &serpent.Command{
Use: "colors",
Hidden: true,
Handler: func(inv *serpent.Invocation) error {
pretty.Fprintf(inv.Stdout, cliui.DefaultStyles.Code, "This is a code message")
_, _ = fmt.Fprintln(inv.Stdout)
pretty.Fprintf(inv.Stdout, cliui.DefaultStyles.DateTimeStamp, "This is a datetimestamp message")
_, _ = fmt.Fprintln(inv.Stdout)
pretty.Fprintf(inv.Stdout, cliui.DefaultStyles.Error, "This is an error message")
_, _ = fmt.Fprintln(inv.Stdout)
pretty.Fprintf(inv.Stdout, cliui.DefaultStyles.Field, "This is a field message")
_, _ = fmt.Fprintln(inv.Stdout)
pretty.Fprintf(inv.Stdout, cliui.DefaultStyles.Keyword, "This is a keyword message")
_, _ = fmt.Fprintln(inv.Stdout)
pretty.Fprintf(inv.Stdout, cliui.DefaultStyles.Placeholder, "This is a placeholder message")
_, _ = fmt.Fprintln(inv.Stdout)
pretty.Fprintf(inv.Stdout, cliui.DefaultStyles.Prompt, "This is a prompt message")
_, _ = fmt.Fprintln(inv.Stdout)
pretty.Fprintf(inv.Stdout, cliui.DefaultStyles.FocusedPrompt, "This is a focused prompt message")
_, _ = fmt.Fprintln(inv.Stdout)
pretty.Fprintf(inv.Stdout, cliui.DefaultStyles.Fuchsia, "This is a fuchsia message")
_, _ = fmt.Fprintln(inv.Stdout)
pretty.Fprintf(inv.Stdout, cliui.DefaultStyles.Warn, "This is a warning message")
_, _ = fmt.Fprintln(inv.Stdout)
return nil
},
})
root.Children = append(root.Children, &serpent.Command{
Use: "prompt",
Handler: func(inv *serpent.Invocation) error {