Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: use ANSI colors codes instead of RGB#14665

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
DanielleMaywood merged 23 commits intomainfromdm-cli-color-theme-change
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
23 commits
Select commitHold shift + click to select a range
5e308df
chore: add command for showing colors
DanielleMaywoodSep 13, 2024
86175bf
fix: use ANSI color codes instead of RGB
DanielleMaywoodSep 13, 2024
098d35d
feat: add '--no-color' flag
DanielleMaywoodSep 13, 2024
3d13060
fix: revert colors
DanielleMaywoodSep 13, 2024
5b8fa3b
chore: change colors
DanielleMaywoodSep 13, 2024
4ce84a4
fix: update golden files
DanielleMaywoodSep 13, 2024
a75dbb2
fix: replace blue with brightBlue
DanielleMaywoodSep 13, 2024
390a7ca
fix: drop '> ' for unfocused prompts
DanielleMaywoodSep 13, 2024
7e6db79
fix: run 'make fmt'
DanielleMaywoodSep 13, 2024
ce913a5
chore: allow disabling color with env flags
DanielleMaywoodSep 13, 2024
22a2d0b
fix: apply fixes from feedback
DanielleMaywoodSep 13, 2024
5e42118
fix: run 'make gen'
DanielleMaywoodSep 13, 2024
40eb24e
fix: refactor janky code
DanielleMaywoodSep 13, 2024
ccf174a
fix: re-add public function
DanielleMaywoodSep 13, 2024
1fbef1d
fix: re-add init for non-color tests
DanielleMaywoodSep 13, 2024
44c3726
fix: move styles to 'init' that can be
DanielleMaywoodSep 13, 2024
d16f625
fix: stop overwriting entire DefaultStyles
DanielleMaywoodSep 13, 2024
1babe96
fix: make code and field obey --no-color
DanielleMaywoodSep 13, 2024
ff3c392
fix: rip out '--no-color' due to race condition
DanielleMaywoodSep 13, 2024
6d93c56
fix: apply nit
DanielleMaywoodSep 13, 2024
506aa28
fix: simplify code && hide command
DanielleMaywoodSep 16, 2024
997dc43
fix: newline shouldn't be themed
DanielleMaywoodSep 16, 2024
24a838d
fix: appease the linter
DanielleMaywoodSep 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 29 additions & 22 deletionscli/cliui/cliui.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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")
Comment on lines +41 to +47
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

nit: indicate these are ANSI color codes

)

// 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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Good solution for disabling colors 👍🏻


if flag.Lookup("test.v") != nil {
// Use a consistent colorless profile in tests so that results
// are deterministic.
Expand DownExpand Up@@ -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!
Expand Down
10 changes: 5 additions & 5 deletionscli/cliui/select.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -256,7 +256,7 @@ func (m selectModel) View() string {
if m.cursor == start+i {
style = pretty.Style{
pretty.Wrap("> ", ""),
pretty.FgColor(Green),
DefaultStyles.Keyword,
}
}

Expand DownExpand Up@@ -481,13 +481,13 @@ func (m multiSelectModel) View() string {
o := option.option

if m.cursor == i {
cursor = pretty.Sprint(pretty.FgColor(Green), "> ")
chosen = pretty.Sprint(pretty.FgColor(Green), "[ ]")
o = pretty.Sprint(pretty.FgColor(Green), o)
cursor = pretty.Sprint(DefaultStyles.Keyword, "> ")
chosen = pretty.Sprint(DefaultStyles.Keyword, "[ ]")
o = pretty.Sprint(DefaultStyles.Keyword, o)
}

if option.chosen {
chosen = pretty.Sprint(pretty.FgColor(Green), "[x]")
chosen = pretty.Sprint(DefaultStyles.Keyword, "[x]")
}

_, _ = s.WriteString(fmt.Sprintf(
Expand Down
39 changes: 39 additions & 0 deletionscmd/cliui/main.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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"
)

Expand All@@ -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 {
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp