Skip to content

Commit ea20ba4

Browse files
committed
change colors
Signed-off-by: Joana Hrotko <[email protected]>
1 parent 2a1a798 commit ea20ba4

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

cmd/formatter/colors.go

+22-4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,20 @@ var names = []string{
3535
"white",
3636
}
3737

38+
const (
39+
BOLD = "1"
40+
FAINT = "2"
41+
ITALIC = "3"
42+
UNDERLINE = "4"
43+
)
44+
45+
type Color string
46+
47+
const (
48+
RESET Color = "0"
49+
CYAN Color = "36"
50+
)
51+
3852
const (
3953
// Never use ANSI codes
4054
Never = "never"
@@ -72,13 +86,17 @@ var monochrome = func(s string) string {
7286
return s
7387
}
7488

75-
func ansiColor(code, s string) string {
76-
return fmt.Sprintf("%s%s%s", ansiColorCode(code), s, ansiColorCode("0"))
89+
func ansiColor(code, s string, formatOpts ...string) string {
90+
return fmt.Sprintf("%s%s%s", ansiColorCode(code, formatOpts...), s, ansiColorCode("0"))
7791
}
7892

7993
// Everything about ansiColorCode color https://hyperskill.org/learn/step/18193
80-
func ansiColorCode(code string) string {
81-
return fmt.Sprintf("\033[%sm", code)
94+
func ansiColorCode(code string, formatOpts ...string) string {
95+
res := "\033["
96+
for _, c := range formatOpts {
97+
res = fmt.Sprintf("%s%s;", res, c)
98+
}
99+
return fmt.Sprintf("%s%sm", res, code)
82100
}
83101

84102
func makeColorFunc(code string) colorFunc {

cmd/formatter/shortcut.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func (ke *KeyboardError) printError(height int, info string) {
6060
func (ke *KeyboardError) addError(prefix string, err error) {
6161
ke.timeStart = time.Now()
6262

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

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

245245
func (lk *LogKeyboard) StartWatch(ctx context.Context, project *types.Project, options api.UpOptions) {
246246
if !lk.IsWatchConfigured {
247-
lk.kError.addError("Watch", fmt.Errorf("Watch is not yet configured. Learn more: %s", ansiColor("36", "https://docs.docker.com/compose/file-watch/")))
247+
lk.kError.addError("Watch", fmt.Errorf("Watch is not yet configured. Learn more: %s", ansiColor(CYAN, "https://docs.docker.com/compose/file-watch/")))
248248
return
249249
}
250250
lk.Watch.switchWatching()
@@ -323,6 +323,5 @@ func shortcutKeyColor(key string) string {
323323
black := "0;0;0"
324324
background := "48;2"
325325
white := "255;255;255"
326-
bold := "1"
327-
return ansiColor(foreground+";"+black+";"+background+";"+white+";"+bold, key)
326+
return ansiColor(foreground+";"+black+";"+background+";"+white, key, BOLD)
328327
}

internal/tracing/keyboard_metrics.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ const (
3030
DEBUG Command = "debug"
3131
)
3232

33-
func NewKeyboardMetrics(IsDockerDesktopActive, isWatchConfigured bool) KeyboardMetrics {
33+
func NewKeyboardMetrics(isDockerDesktopActive, isWatchConfigured bool) KeyboardMetrics {
3434
metrics := KeyboardMetrics{
3535
enabled: true,
3636
commandAvailable: []Command{},
3737
}
38-
if IsDockerDesktopActive {
38+
if isDockerDesktopActive {
3939
metrics.commandAvailable = append(metrics.commandAvailable, GUI)
4040
}
4141
if isWatchConfigured {

0 commit comments

Comments
 (0)