Skip to content

Move terminal colors to global constants #913

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions cmd/cmd_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import (
"strings"
"time"

"github.com/fatih/color"
"github.com/spf13/cobra"

e "github.com/cloudposse/atmos/internal/exec"
tuiUtils "github.com/cloudposse/atmos/internal/tui/utils"
cfg "github.com/cloudposse/atmos/pkg/config"
"github.com/cloudposse/atmos/pkg/schema"
"github.com/cloudposse/atmos/pkg/ui/theme"
u "github.com/cloudposse/atmos/pkg/utils"
"github.com/cloudposse/atmos/pkg/version"
)
Expand Down Expand Up @@ -448,8 +448,8 @@ func checkAtmosConfig(opts ...AtmosValidateOption) {

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

fmt.Println()
err := tuiUtils.PrintStyledText("ATMOS")
Expand Down
9 changes: 5 additions & 4 deletions cmd/list_components.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/cloudposse/atmos/pkg/config"
l "github.com/cloudposse/atmos/pkg/list"
"github.com/cloudposse/atmos/pkg/schema"
"github.com/cloudposse/atmos/pkg/ui/theme"
u "github.com/cloudposse/atmos/pkg/utils"
)

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

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

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

u.PrintMessageInColor(output, color.New(color.FgGreen))
u.PrintMessageInColor(output, theme.Colors.Success)
},
}

Expand Down
10 changes: 5 additions & 5 deletions cmd/list_stacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package cmd
import (
"fmt"

"github.com/fatih/color"
"github.com/spf13/cobra"

e "github.com/cloudposse/atmos/internal/exec"
"github.com/cloudposse/atmos/pkg/config"
l "github.com/cloudposse/atmos/pkg/list"
"github.com/cloudposse/atmos/pkg/schema"
"github.com/cloudposse/atmos/pkg/ui/theme"
u "github.com/cloudposse/atmos/pkg/utils"
)

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

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

output, err := l.FilterAndListStacks(stacksMap, componentFlag)
if err != nil {
u.PrintMessageInColor(fmt.Sprintf("Error filtering stacks: %v", err), color.New(color.FgRed))
u.PrintMessageInColor(fmt.Sprintf("Error filtering stacks: %v", err), theme.Colors.Error)
return
}
u.PrintMessageInColor(output, color.New(color.FgGreen))
u.PrintMessageInColor(output, theme.Colors.Success)
},
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/validate_component.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package cmd
import (
"fmt"

"github.com/fatih/color"
"github.com/spf13/cobra"

e "github.com/cloudposse/atmos/internal/exec"
"github.com/cloudposse/atmos/pkg/schema"
"github.com/cloudposse/atmos/pkg/ui/theme"
u "github.com/cloudposse/atmos/pkg/utils"
)

Expand All @@ -30,7 +30,7 @@ var validateComponentCmd = &cobra.Command{
}

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

Expand Down
4 changes: 2 additions & 2 deletions cmd/validate_stacks.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package cmd

import (
"github.com/fatih/color"
"github.com/spf13/cobra"

e "github.com/cloudposse/atmos/internal/exec"
"github.com/cloudposse/atmos/pkg/schema"
"github.com/cloudposse/atmos/pkg/ui/theme"
u "github.com/cloudposse/atmos/pkg/utils"
)

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

u.PrintMessageInColor("all stacks validated successfully\n", color.New(color.FgGreen))
u.PrintMessageInColor("all stacks validated successfully\n", theme.Colors.Success)
},
}

Expand Down
6 changes: 3 additions & 3 deletions internal/exec/atmos.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import (
"os"
"strings"

"github.com/fatih/color"
"github.com/samber/lo"

tui "github.com/cloudposse/atmos/internal/tui/atmos"
cfg "github.com/cloudposse/atmos/pkg/config"
"github.com/cloudposse/atmos/pkg/schema"
"github.com/cloudposse/atmos/pkg/ui/theme"
u "github.com/cloudposse/atmos/pkg/utils"
)

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

Expand Down Expand Up @@ -134,7 +134,7 @@ func ExecuteAtmosCmd() error {
}

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

Expand Down
7 changes: 4 additions & 3 deletions internal/exec/terraform_clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/charmbracelet/huh"
"github.com/charmbracelet/lipgloss"
"github.com/cloudposse/atmos/pkg/schema"
"github.com/cloudposse/atmos/pkg/ui/theme"
u "github.com/cloudposse/atmos/pkg/utils"
)

Expand Down Expand Up @@ -256,7 +257,7 @@ func confirmDeleteTerraformLocal(message string) (confirm bool, err error) {
func DeletePathTerraform(fullPath string, objectName string) error {
fileInfo, err := os.Lstat(fullPath)
if os.IsNotExist(err) {
xMark := lipgloss.NewStyle().Foreground(lipgloss.Color("9")).SetString("x")
xMark := theme.Styles.XMark
fmt.Printf("%s Cannot delete %s: path does not exist", xMark, objectName)
fmt.Println()
return err
Expand All @@ -267,12 +268,12 @@ func DeletePathTerraform(fullPath string, objectName string) error {
// Proceed with deletion
err = os.RemoveAll(fullPath)
if err != nil {
xMark := lipgloss.NewStyle().Foreground(lipgloss.Color("9")).SetString("x")
xMark := theme.Styles.XMark
fmt.Printf("%s Error deleting %s", xMark, objectName)
fmt.Println()
return err
}
checkMark := lipgloss.NewStyle().Foreground(lipgloss.Color("42")).SetString("✓")
checkMark := theme.Styles.Checkmark
fmt.Printf("%s Deleted %s", checkMark, objectName)
fmt.Println()
return nil
Expand Down
11 changes: 6 additions & 5 deletions internal/exec/vendor_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/cloudposse/atmos/pkg/schema"
"github.com/cloudposse/atmos/pkg/ui/theme"
u "github.com/cloudposse/atmos/pkg/utils"
"github.com/hashicorp/go-getter"
cp "github.com/otiai10/copy"
Expand Down Expand Up @@ -67,11 +68,11 @@ type modelVendor struct {
}

var (
currentPkgNameStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("211"))
currentPkgNameStyle = theme.Styles.PackageName
doneStyle = lipgloss.NewStyle().Margin(1, 2)
checkMark = lipgloss.NewStyle().Foreground(lipgloss.Color("42")).SetString("✓")
xMark = lipgloss.NewStyle().Foreground(lipgloss.Color("9")).SetString("x")
grayColor = lipgloss.NewStyle().Foreground(lipgloss.Color("241"))
checkMark = theme.Styles.Checkmark
xMark = theme.Styles.XMark
grayColor = theme.Styles.GrayText
)

func newModelAtmosVendorInternal(pkgs []pkgAtmosVendor, dryRun bool, atmosConfig schema.AtmosConfiguration) (modelVendor, error) {
Expand All @@ -81,7 +82,7 @@ func newModelAtmosVendorInternal(pkgs []pkgAtmosVendor, dryRun bool, atmosConfig
progress.WithoutPercentage(),
)
s := spinner.New()
s.Style = lipgloss.NewStyle().Foreground(lipgloss.Color("63"))
s.Style = theme.Styles.Link
if len(pkgs) == 0 {
return modelVendor{done: true}, nil
}
Expand Down
4 changes: 2 additions & 2 deletions internal/exec/vendor_model_component.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"github.com/charmbracelet/bubbles/progress"
"github.com/charmbracelet/bubbles/spinner"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/cloudposse/atmos/pkg/schema"
"github.com/cloudposse/atmos/pkg/ui/theme"
"github.com/hashicorp/go-getter"
cp "github.com/otiai10/copy"
)
Expand All @@ -37,7 +37,7 @@ func newModelComponentVendorInternal(pkgs []pkgComponentVendor, dryRun bool, atm
progress.WithoutPercentage(),
)
s := spinner.New()
s.Style = lipgloss.NewStyle().Foreground(lipgloss.Color("63"))
s.Style = theme.Styles.Link
if len(pkgs) == 0 {
return modelVendor{done: true}, nil
}
Expand Down
8 changes: 4 additions & 4 deletions internal/exec/workflow_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import (
"sort"
"strings"

"github.com/fatih/color"
"github.com/pkg/errors"
"github.com/samber/lo"

w "github.com/cloudposse/atmos/internal/tui/workflow"
"github.com/cloudposse/atmos/pkg/schema"
"github.com/cloudposse/atmos/pkg/ui/theme"
u "github.com/cloudposse/atmos/pkg/utils"
)

Expand Down Expand Up @@ -109,12 +109,12 @@ func ExecuteWorkflow(
workflowFileName := filepath.Base(workflowPath)
workflowFileName = strings.TrimSuffix(workflowFileName, filepath.Ext(workflowFileName))

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

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

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

Expand Down
3 changes: 2 additions & 1 deletion internal/tui/atmos/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/charmbracelet/bubbles/list"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/cloudposse/atmos/pkg/ui/theme"
mouseZone "github.com/lrstanley/bubblezone"
)

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

if c.Focused() {
s = s.Border(lipgloss.RoundedBorder()).BorderForeground(lipgloss.Color("62"))
s = s.Border(lipgloss.RoundedBorder()).BorderForeground(lipgloss.Color(theme.ColorBorder))
} else {
s = s.Border(lipgloss.HiddenBorder())
}
Expand Down
3 changes: 2 additions & 1 deletion internal/tui/atmos/list_item.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import (
"github.com/charmbracelet/bubbles/list"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/cloudposse/atmos/pkg/ui/theme"
)

var (
itemStyle = lipgloss.NewStyle().PaddingLeft(4)
selectedItemStyle = lipgloss.NewStyle().PaddingLeft(2).Foreground(lipgloss.Color("#10ff10"))
selectedItemStyle = theme.Styles.SelectedItem
)

type listItem string
Expand Down
17 changes: 7 additions & 10 deletions internal/tui/templates/templater.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"

"github.com/charmbracelet/lipgloss"
"github.com/cloudposse/atmos/pkg/ui/theme"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"golang.org/x/term"
Expand All @@ -19,18 +20,14 @@ type Templater struct {

// commandStyle defines the styles for command formatting
var (
commandNameStyle = lipgloss.NewStyle().
Foreground(lipgloss.Color("2")). // Green color for command name
Bold(true)
commandNameStyle = theme.Styles.CommandName
commandDescStyle = theme.Styles.Description

commandDescStyle = lipgloss.NewStyle().
Foreground(lipgloss.Color("7")) // White color for description

commandUnsupportedNameStyle = lipgloss.NewStyle().
Foreground(lipgloss.Color("8")).
commandUnsupportedNameStyle = theme.Styles.CommandName.
Foreground(lipgloss.Color(theme.ColorGray)).
Bold(true)
commandUnsupportedDescStyle = lipgloss.NewStyle().
Foreground(lipgloss.Color("8"))
commandUnsupportedDescStyle = theme.Styles.Description.
Foreground(lipgloss.Color(theme.ColorGray))
)

// formatCommand returns a styled string for a command and its description
Expand Down
6 changes: 3 additions & 3 deletions internal/tui/workflow/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"github.com/charmbracelet/bubbles/list"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
mouseZone "github.com/lrstanley/bubblezone"

codeview "github.com/cloudposse/atmos/internal/tui/components/code_view"
"github.com/cloudposse/atmos/pkg/ui/theme"
mouseZone "github.com/lrstanley/bubblezone"
)

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

if c.Focused() {
s = s.Border(lipgloss.RoundedBorder()).BorderForeground(lipgloss.Color("62"))
s = s.Border(lipgloss.RoundedBorder()).BorderForeground(lipgloss.Color(theme.ColorBorder))
} else {
s = s.Border(lipgloss.HiddenBorder())
}
Expand Down
Loading
Loading