Skip to content

Commit

Permalink
change colors
Browse files Browse the repository at this point in the history
Signed-off-by: Joana Hrotko <joana.hrotko@docker.com>
  • Loading branch information
jhrotko committed Mar 20, 2024
1 parent aec5805 commit 610917c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
26 changes: 22 additions & 4 deletions cmd/formatter/colors.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,20 @@ var names = []string{
"white",
}

const (
BOLD = "1"
FAINT = "2"
ITALIC = "3"
UNDERLINE = "4"
)

type Color string

const (
RESET Color = "0"
CYAN Color = "36"
)

const (
// Never use ANSI codes
Never = "never"
Expand Down Expand Up @@ -72,13 +86,17 @@ var monochrome = func(s string) string {
return s
}

func ansiColor(code, s string) string {
return fmt.Sprintf("%s%s%s", ansiColorCode(code), s, ansiColorCode("0"))
func ansiColor(code, s string, formatOpts ...string) string {
return fmt.Sprintf("%s%s%s", ansiColorCode(code, formatOpts...), s, ansiColorCode("0"))
}

// Everything about ansiColorCode color https://hyperskill.org/learn/step/18193
func ansiColorCode(code string) string {
return fmt.Sprintf("\033[%sm", code)
func ansiColorCode(code string, formatOpts ...string) string {
res := "\033["
for _, c := range formatOpts {
res = fmt.Sprintf("%s%s;", res, c)
}
return fmt.Sprintf("%s%sm", res, code)
}

func makeColorFunc(code string) colorFunc {
Expand Down
7 changes: 3 additions & 4 deletions cmd/formatter/shortcut.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (ke *KeyboardError) printError(height int, info string) {
func (ke *KeyboardError) addError(prefix string, err error) {
ke.timeStart = time.Now()

prefix = ansiColor("1;36", fmt.Sprintf("%s →", prefix))
prefix = ansiColor(CYAN, fmt.Sprintf("%s →", prefix), BOLD)
errorString := fmt.Sprintf("%s %s", prefix, err.Error())

ke.err = errors.New(errorString)
Expand Down Expand Up @@ -244,7 +244,7 @@ func (lk *LogKeyboard) openDockerDesktop(project *types.Project) {

func (lk *LogKeyboard) StartWatch(ctx context.Context, project *types.Project, options api.UpOptions) {
if !lk.IsWatchConfigured {
lk.kError.addError("Watch", fmt.Errorf("Watch is not yet configured. Learn more: %s", ansiColor("36", "https://docs.docker.com/compose/file-watch/")))
lk.kError.addError("Watch", fmt.Errorf("Watch is not yet configured. Learn more: %s", ansiColor(CYAN, "https://docs.docker.com/compose/file-watch/")))
return
}
lk.Watch.switchWatching()
Expand Down Expand Up @@ -323,6 +323,5 @@ func shortcutKeyColor(key string) string {
black := "0;0;0"
background := "48;2"
white := "255;255;255"
bold := "1"
return ansiColor(foreground+";"+black+";"+background+";"+white+";"+bold, key)
return ansiColor(foreground+";"+black+";"+background+";"+white, key, BOLD)
}
4 changes: 2 additions & 2 deletions internal/tracing/keyboard_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ const (
DEBUG Command = "debug"
)

func NewKeyboardMetrics(IsDockerDesktopActive, isWatchConfigured bool) KeyboardMetrics {
func NewKeyboardMetrics(isDockerDesktopActive, isWatchConfigured bool) KeyboardMetrics {
metrics := KeyboardMetrics{
enabled: true,
commandAvailable: []Command{},
}
if IsDockerDesktopActive {
if isDockerDesktopActive {
metrics.commandAvailable = append(metrics.commandAvailable, GUI)
}
if isWatchConfigured {
Expand Down

0 comments on commit 610917c

Please sign in to comment.