Skip to content

Commit 9c1a23a

Browse files
Cerebrovinnyaknysh
andauthored
Move terminal colors to global constants (#913)
* added new theme * change pkg to use theme colors * revert merge * revert logger * cmd utils update theme colors * list_components update theme colors * list_stacks update theme colors * terraform_clean update theme colors * atmos update theme colors * tui update theme colors * exec update theme colors * stacks update theme colors * update pkgs for new theme colors * Revert "update pkgs for new theme colors" This reverts commit 7c63ea3. * hex colors * update internal/exec/atmos.go for new theme colors --------- Co-authored-by: Andriy Knysh <[email protected]>
1 parent f05aee6 commit 9c1a23a

21 files changed

+153
-94
lines changed

cmd/cmd_utils.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ import (
99
"strings"
1010
"time"
1111

12-
"github.com/fatih/color"
1312
"github.com/spf13/cobra"
1413

1514
e "github.com/cloudposse/atmos/internal/exec"
1615
tuiUtils "github.com/cloudposse/atmos/internal/tui/utils"
1716
cfg "github.com/cloudposse/atmos/pkg/config"
1817
"github.com/cloudposse/atmos/pkg/schema"
18+
"github.com/cloudposse/atmos/pkg/ui/theme"
1919
u "github.com/cloudposse/atmos/pkg/utils"
2020
"github.com/cloudposse/atmos/pkg/version"
2121
)
@@ -448,8 +448,8 @@ func checkAtmosConfig(opts ...AtmosValidateOption) {
448448

449449
// printMessageForMissingAtmosConfig prints Atmos logo and instructions on how to configure and start using Atmos
450450
func printMessageForMissingAtmosConfig(atmosConfig schema.AtmosConfiguration) {
451-
c1 := color.New(color.FgCyan)
452-
c2 := color.New(color.FgGreen)
451+
c1 := theme.Colors.Info
452+
c2 := theme.Colors.Success
453453

454454
fmt.Println()
455455
err := tuiUtils.PrintStyledText("ATMOS")

cmd/list_components.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/cloudposse/atmos/pkg/config"
1111
l "github.com/cloudposse/atmos/pkg/list"
1212
"github.com/cloudposse/atmos/pkg/schema"
13+
"github.com/cloudposse/atmos/pkg/ui/theme"
1314
u "github.com/cloudposse/atmos/pkg/utils"
1415
)
1516

@@ -35,23 +36,23 @@ var listComponentsCmd = &cobra.Command{
3536
configAndStacksInfo := schema.ConfigAndStacksInfo{}
3637
atmosConfig, err := config.InitCliConfig(configAndStacksInfo, true)
3738
if err != nil {
38-
u.PrintMessageInColor(fmt.Sprintf("Error initializing CLI config: %v", err), color.New(color.FgRed))
39+
u.PrintMessageInColor(fmt.Sprintf("Error initializing CLI config: %v", err), theme.Colors.Error)
3940
return
4041
}
4142

4243
stacksMap, err := e.ExecuteDescribeStacks(atmosConfig, "", nil, nil, nil, false, false, false)
4344
if err != nil {
44-
u.PrintMessageInColor(fmt.Sprintf("Error describing stacks: %v", err), color.New(color.FgRed))
45+
u.PrintMessageInColor(fmt.Sprintf("Error describing stacks: %v", err), theme.Colors.Error)
4546
return
4647
}
4748

4849
output, err := l.FilterAndListComponents(stackFlag, stacksMap)
4950
if err != nil {
50-
u.PrintMessageInColor(fmt.Sprintf("Error: %v"+"\n", err), color.New(color.FgYellow))
51+
u.PrintMessageInColor(fmt.Sprintf("Error: %v"+"\n", err), theme.Colors.Warning)
5152
return
5253
}
5354

54-
u.PrintMessageInColor(output, color.New(color.FgGreen))
55+
u.PrintMessageInColor(output, theme.Colors.Success)
5556
},
5657
}
5758

cmd/list_stacks.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ package cmd
33
import (
44
"fmt"
55

6-
"github.com/fatih/color"
76
"github.com/spf13/cobra"
87

98
e "github.com/cloudposse/atmos/internal/exec"
109
"github.com/cloudposse/atmos/pkg/config"
1110
l "github.com/cloudposse/atmos/pkg/list"
1211
"github.com/cloudposse/atmos/pkg/schema"
12+
"github.com/cloudposse/atmos/pkg/ui/theme"
1313
u "github.com/cloudposse/atmos/pkg/utils"
1414
)
1515

@@ -30,22 +30,22 @@ var listStacksCmd = &cobra.Command{
3030
configAndStacksInfo := schema.ConfigAndStacksInfo{}
3131
atmosConfig, err := config.InitCliConfig(configAndStacksInfo, true)
3232
if err != nil {
33-
u.PrintMessageInColor(fmt.Sprintf("Error initializing CLI config: %v", err), color.New(color.FgRed))
33+
u.PrintMessageInColor(fmt.Sprintf("Error initializing CLI config: %v", err), theme.Colors.Error)
3434
return
3535
}
3636

3737
stacksMap, err := e.ExecuteDescribeStacks(atmosConfig, "", nil, nil, nil, false, false, false)
3838
if err != nil {
39-
u.PrintMessageInColor(fmt.Sprintf("Error describing stacks: %v", err), color.New(color.FgRed))
39+
u.PrintMessageInColor(fmt.Sprintf("Error describing stacks: %v", err), theme.Colors.Error)
4040
return
4141
}
4242

4343
output, err := l.FilterAndListStacks(stacksMap, componentFlag)
4444
if err != nil {
45-
u.PrintMessageInColor(fmt.Sprintf("Error filtering stacks: %v", err), color.New(color.FgRed))
45+
u.PrintMessageInColor(fmt.Sprintf("Error filtering stacks: %v", err), theme.Colors.Error)
4646
return
4747
}
48-
u.PrintMessageInColor(output, color.New(color.FgGreen))
48+
u.PrintMessageInColor(output, theme.Colors.Success)
4949
},
5050
}
5151

cmd/validate_component.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ package cmd
33
import (
44
"fmt"
55

6-
"github.com/fatih/color"
76
"github.com/spf13/cobra"
87

98
e "github.com/cloudposse/atmos/internal/exec"
109
"github.com/cloudposse/atmos/pkg/schema"
10+
"github.com/cloudposse/atmos/pkg/ui/theme"
1111
u "github.com/cloudposse/atmos/pkg/utils"
1212
)
1313

@@ -30,7 +30,7 @@ var validateComponentCmd = &cobra.Command{
3030
}
3131

3232
m := fmt.Sprintf("component '%s' in stack '%s' validated successfully\n", component, stack)
33-
u.PrintMessageInColor(m, color.New(color.FgGreen))
33+
u.PrintMessageInColor(m, theme.Colors.Success)
3434
},
3535
}
3636

cmd/validate_stacks.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package cmd
22

33
import (
4-
"github.com/fatih/color"
54
"github.com/spf13/cobra"
65

76
e "github.com/cloudposse/atmos/internal/exec"
87
"github.com/cloudposse/atmos/pkg/schema"
8+
"github.com/cloudposse/atmos/pkg/ui/theme"
99
u "github.com/cloudposse/atmos/pkg/utils"
1010
)
1111

@@ -25,7 +25,7 @@ var ValidateStacksCmd = &cobra.Command{
2525
u.LogErrorAndExit(schema.AtmosConfiguration{}, err)
2626
}
2727

28-
u.PrintMessageInColor("all stacks validated successfully\n", color.New(color.FgGreen))
28+
u.PrintMessageInColor("all stacks validated successfully\n", theme.Colors.Success)
2929
},
3030
}
3131

internal/exec/atmos.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import (
55
"os"
66
"strings"
77

8-
"github.com/fatih/color"
98
"github.com/samber/lo"
109

1110
tui "github.com/cloudposse/atmos/internal/tui/atmos"
1211
cfg "github.com/cloudposse/atmos/pkg/config"
1312
"github.com/cloudposse/atmos/pkg/schema"
13+
"github.com/cloudposse/atmos/pkg/ui/theme"
1414
u "github.com/cloudposse/atmos/pkg/utils"
1515
)
1616

@@ -99,7 +99,7 @@ func ExecuteAtmosCmd() error {
9999
fmt.Println()
100100
u.PrintMessageInColor(fmt.Sprintf(
101101
"Executing command:\n"+os.Args[0]+" %s %s --stack %s\n", selectedCommand, selectedComponent, selectedStack),
102-
color.New(color.FgCyan),
102+
theme.Colors.Info,
103103
)
104104
fmt.Println()
105105

@@ -134,7 +134,7 @@ func ExecuteAtmosCmd() error {
134134
}
135135

136136
m := fmt.Sprintf("component '%s' in stack '%s' validated successfully\n", selectedComponent, selectedStack)
137-
u.PrintMessageInColor(m, color.New(color.FgGreen))
137+
u.PrintMessageInColor(m, theme.Colors.Success)
138138
return nil
139139
}
140140

internal/exec/terraform_clean.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/charmbracelet/huh"
1010
"github.com/charmbracelet/lipgloss"
1111
"github.com/cloudposse/atmos/pkg/schema"
12+
"github.com/cloudposse/atmos/pkg/ui/theme"
1213
u "github.com/cloudposse/atmos/pkg/utils"
1314
)
1415

@@ -256,7 +257,7 @@ func confirmDeleteTerraformLocal(message string) (confirm bool, err error) {
256257
func DeletePathTerraform(fullPath string, objectName string) error {
257258
fileInfo, err := os.Lstat(fullPath)
258259
if os.IsNotExist(err) {
259-
xMark := lipgloss.NewStyle().Foreground(lipgloss.Color("9")).SetString("x")
260+
xMark := theme.Styles.XMark
260261
fmt.Printf("%s Cannot delete %s: path does not exist", xMark, objectName)
261262
fmt.Println()
262263
return err
@@ -267,12 +268,12 @@ func DeletePathTerraform(fullPath string, objectName string) error {
267268
// Proceed with deletion
268269
err = os.RemoveAll(fullPath)
269270
if err != nil {
270-
xMark := lipgloss.NewStyle().Foreground(lipgloss.Color("9")).SetString("x")
271+
xMark := theme.Styles.XMark
271272
fmt.Printf("%s Error deleting %s", xMark, objectName)
272273
fmt.Println()
273274
return err
274275
}
275-
checkMark := lipgloss.NewStyle().Foreground(lipgloss.Color("42")).SetString("✓")
276+
checkMark := theme.Styles.Checkmark
276277
fmt.Printf("%s Deleted %s", checkMark, objectName)
277278
fmt.Println()
278279
return nil

internal/exec/vendor_model.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
tea "github.com/charmbracelet/bubbletea"
1515
"github.com/charmbracelet/lipgloss"
1616
"github.com/cloudposse/atmos/pkg/schema"
17+
"github.com/cloudposse/atmos/pkg/ui/theme"
1718
u "github.com/cloudposse/atmos/pkg/utils"
1819
"github.com/hashicorp/go-getter"
1920
cp "github.com/otiai10/copy"
@@ -67,11 +68,11 @@ type modelVendor struct {
6768
}
6869

6970
var (
70-
currentPkgNameStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("211"))
71+
currentPkgNameStyle = theme.Styles.PackageName
7172
doneStyle = lipgloss.NewStyle().Margin(1, 2)
72-
checkMark = lipgloss.NewStyle().Foreground(lipgloss.Color("42")).SetString("✓")
73-
xMark = lipgloss.NewStyle().Foreground(lipgloss.Color("9")).SetString("x")
74-
grayColor = lipgloss.NewStyle().Foreground(lipgloss.Color("241"))
73+
checkMark = theme.Styles.Checkmark
74+
xMark = theme.Styles.XMark
75+
grayColor = theme.Styles.GrayText
7576
)
7677

7778
func newModelAtmosVendorInternal(pkgs []pkgAtmosVendor, dryRun bool, atmosConfig schema.AtmosConfiguration) (modelVendor, error) {
@@ -81,7 +82,7 @@ func newModelAtmosVendorInternal(pkgs []pkgAtmosVendor, dryRun bool, atmosConfig
8182
progress.WithoutPercentage(),
8283
)
8384
s := spinner.New()
84-
s.Style = lipgloss.NewStyle().Foreground(lipgloss.Color("63"))
85+
s.Style = theme.Styles.Link
8586
if len(pkgs) == 0 {
8687
return modelVendor{done: true}, nil
8788
}

internal/exec/vendor_model_component.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111
"github.com/charmbracelet/bubbles/progress"
1212
"github.com/charmbracelet/bubbles/spinner"
1313
tea "github.com/charmbracelet/bubbletea"
14-
"github.com/charmbracelet/lipgloss"
1514
"github.com/cloudposse/atmos/pkg/schema"
15+
"github.com/cloudposse/atmos/pkg/ui/theme"
1616
"github.com/hashicorp/go-getter"
1717
cp "github.com/otiai10/copy"
1818
)
@@ -37,7 +37,7 @@ func newModelComponentVendorInternal(pkgs []pkgComponentVendor, dryRun bool, atm
3737
progress.WithoutPercentage(),
3838
)
3939
s := spinner.New()
40-
s.Style = lipgloss.NewStyle().Foreground(lipgloss.Color("63"))
40+
s.Style = theme.Styles.Link
4141
if len(pkgs) == 0 {
4242
return modelVendor{done: true}, nil
4343
}

internal/exec/workflow_utils.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import (
77
"sort"
88
"strings"
99

10-
"github.com/fatih/color"
1110
"github.com/pkg/errors"
1211
"github.com/samber/lo"
1312

1413
w "github.com/cloudposse/atmos/internal/tui/workflow"
1514
"github.com/cloudposse/atmos/pkg/schema"
15+
"github.com/cloudposse/atmos/pkg/ui/theme"
1616
u "github.com/cloudposse/atmos/pkg/utils"
1717
)
1818

@@ -109,12 +109,12 @@ func ExecuteWorkflow(
109109
workflowFileName := filepath.Base(workflowPath)
110110
workflowFileName = strings.TrimSuffix(workflowFileName, filepath.Ext(workflowFileName))
111111

112-
failedMsg := color.New(color.FgRed).Sprintf("\nStep '%s' failed!", step.Name)
112+
failedMsg := theme.Colors.Error.Sprintf("\nStep '%s' failed!", step.Name)
113113

114114
u.LogDebug(atmosConfig, fmt.Sprintf("\nCommand failed: %s", command))
115115
u.LogDebug(atmosConfig, fmt.Sprintf("Error: %v", err))
116116

117-
resumeMsg := color.New(color.FgGreen).Sprintf(
117+
resumeMsg := theme.Colors.Success.Sprintf(
118118
"\nTo resume the workflow from this step, run:\natmos workflow %s -f %s --from-step %s",
119119
workflow,
120120
workflowFileName,
@@ -256,7 +256,7 @@ func ExecuteWorkflowUI(atmosConfig schema.AtmosConfiguration) (string, string, s
256256
fmt.Println()
257257
u.PrintMessageInColor(fmt.Sprintf(
258258
"Executing command:\n"+os.Args[0]+" workflow %s --file %s --from-step \"%s\"\n", selectedWorkflow, selectedWorkflowFile, selectedWorkflowStep),
259-
color.New(color.FgCyan),
259+
theme.Colors.Info,
260260
)
261261
fmt.Println()
262262

internal/tui/atmos/column.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"github.com/charmbracelet/bubbles/list"
55
tea "github.com/charmbracelet/bubbletea"
66
"github.com/charmbracelet/lipgloss"
7+
"github.com/cloudposse/atmos/pkg/ui/theme"
78
mouseZone "github.com/lrstanley/bubblezone"
89
)
910

@@ -72,7 +73,7 @@ func (c *columnView) getStyle() lipgloss.Style {
7273
s := lipgloss.NewStyle().Padding(1, 2).Height(c.height).Width(c.width)
7374

7475
if c.Focused() {
75-
s = s.Border(lipgloss.RoundedBorder()).BorderForeground(lipgloss.Color("62"))
76+
s = s.Border(lipgloss.RoundedBorder()).BorderForeground(lipgloss.Color(theme.ColorBorder))
7677
} else {
7778
s = s.Border(lipgloss.HiddenBorder())
7879
}

internal/tui/atmos/list_item.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ import (
88
"github.com/charmbracelet/bubbles/list"
99
tea "github.com/charmbracelet/bubbletea"
1010
"github.com/charmbracelet/lipgloss"
11+
"github.com/cloudposse/atmos/pkg/ui/theme"
1112
)
1213

1314
var (
1415
itemStyle = lipgloss.NewStyle().PaddingLeft(4)
15-
selectedItemStyle = lipgloss.NewStyle().PaddingLeft(2).Foreground(lipgloss.Color("#10ff10"))
16+
selectedItemStyle = theme.Styles.SelectedItem
1617
)
1718

1819
type listItem string

internal/tui/templates/templater.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"strings"
88

99
"github.com/charmbracelet/lipgloss"
10+
"github.com/cloudposse/atmos/pkg/ui/theme"
1011
"github.com/spf13/cobra"
1112
"github.com/spf13/pflag"
1213
"golang.org/x/term"
@@ -19,18 +20,14 @@ type Templater struct {
1920

2021
// commandStyle defines the styles for command formatting
2122
var (
22-
commandNameStyle = lipgloss.NewStyle().
23-
Foreground(lipgloss.Color("2")). // Green color for command name
24-
Bold(true)
23+
commandNameStyle = theme.Styles.CommandName
24+
commandDescStyle = theme.Styles.Description
2525

26-
commandDescStyle = lipgloss.NewStyle().
27-
Foreground(lipgloss.Color("7")) // White color for description
28-
29-
commandUnsupportedNameStyle = lipgloss.NewStyle().
30-
Foreground(lipgloss.Color("8")).
26+
commandUnsupportedNameStyle = theme.Styles.CommandName.
27+
Foreground(lipgloss.Color(theme.ColorGray)).
3128
Bold(true)
32-
commandUnsupportedDescStyle = lipgloss.NewStyle().
33-
Foreground(lipgloss.Color("8"))
29+
commandUnsupportedDescStyle = theme.Styles.Description.
30+
Foreground(lipgloss.Color(theme.ColorGray))
3431
)
3532

3633
// formatCommand returns a styled string for a command and its description

internal/tui/workflow/column.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import (
44
"github.com/charmbracelet/bubbles/list"
55
tea "github.com/charmbracelet/bubbletea"
66
"github.com/charmbracelet/lipgloss"
7-
mouseZone "github.com/lrstanley/bubblezone"
8-
97
codeview "github.com/cloudposse/atmos/internal/tui/components/code_view"
8+
"github.com/cloudposse/atmos/pkg/ui/theme"
9+
mouseZone "github.com/lrstanley/bubblezone"
1010
)
1111

1212
const (
@@ -142,7 +142,7 @@ func (c *columnView) getStyle() lipgloss.Style {
142142
s := lipgloss.NewStyle().Padding(0).Margin(2).Height(c.height).Width(c.width)
143143

144144
if c.Focused() {
145-
s = s.Border(lipgloss.RoundedBorder()).BorderForeground(lipgloss.Color("62"))
145+
s = s.Border(lipgloss.RoundedBorder()).BorderForeground(lipgloss.Color(theme.ColorBorder))
146146
} else {
147147
s = s.Border(lipgloss.HiddenBorder())
148148
}

0 commit comments

Comments
 (0)