Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
1fff23f
add no-color support for atmos
samtholiya Apr 30, 2025
4cd8889
fix test case error
samtholiya Apr 30, 2025
896b4ef
fix test case
samtholiya May 1, 2025
d7c7fc6
fix tests
samtholiya May 1, 2025
59964b0
Merge branch 'main' into feature/dev-3177--no-color-should-be-a-globa…
samtholiya May 1, 2025
5f5cab2
removed editorconfig color parameter
samtholiya May 1, 2025
e38d2e4
Merge branch 'feature/dev-3177--no-color-should-be-a-global-flag' of …
samtholiya May 1, 2025
159ac32
fixed test case
samtholiya May 1, 2025
6d28396
configuration refactor
samtholiya May 1, 2025
5bf115e
add test case for color vs no-color
samtholiya May 1, 2025
cd8d695
[autofix.ci] apply automated fixes
autofix-ci[bot] May 1, 2025
139ffb4
added test for no color
samtholiya May 1, 2025
3e82d10
Merge branch 'feature/dev-3177--no-color-should-be-a-global-flag' of …
samtholiya May 1, 2025
d1b9045
added tests
samtholiya May 1, 2025
14534fb
fix logging render
samtholiya May 1, 2025
31aff06
fix lint
samtholiya May 1, 2025
61e1c7f
fix exception
samtholiya May 1, 2025
2bf2e0b
fix tests
samtholiya May 1, 2025
8737e9d
fix tests
samtholiya May 1, 2025
a0890d6
add test coverage
samtholiya May 1, 2025
b7fc01b
add more test coverage
samtholiya May 1, 2025
c832868
try fix
samtholiya May 2, 2025
d05600e
revert support test to check windows
samtholiya May 4, 2025
31e182c
configuration markdown update
samtholiya May 4, 2025
08f3dc1
added more test case
samtholiya May 4, 2025
8f70892
fix test case
samtholiya May 4, 2025
d6a02ed
revert the change
samtholiya May 4, 2025
6aff052
add logs to the test
samtholiya May 4, 2025
de270f7
added more logs
samtholiya May 4, 2025
131249b
check this
samtholiya May 4, 2025
feb782c
test windows check
samtholiya May 4, 2025
992c98b
support test case added
samtholiya May 4, 2025
39bbe6c
added documentation
samtholiya May 5, 2025
efd3bf7
Merge branch 'main' into feature/dev-3177--no-color-should-be-a-globa…
samtholiya May 8, 2025
7a5c193
Fix code rabbit comment
samtholiya May 9, 2025
3cc559b
Merge branch 'main' into feature/dev-3177--no-color-should-be-a-globa…
samtholiya May 9, 2025
f6742a1
Merge branch 'main' into feature/dev-3177--no-color-should-be-a-globa…
Benbentwo May 14, 2025
ba10aad
[autofix.ci] apply automated fixes
autofix-ci[bot] May 14, 2025
765da27
update tests
Benbentwo May 14, 2025
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
12 changes: 12 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,17 @@
log.SetLevel(log.InfoLevel)
}

if atmosConfig.Settings.Terminal.NoColor {
styles := log.DefaultStyles()
// Clear colors for levels
styles.Levels[log.DebugLevel] = styles.Levels[log.DebugLevel].UnsetForeground()
styles.Levels[log.InfoLevel] = styles.Levels[log.InfoLevel].UnsetForeground()
styles.Levels[log.WarnLevel] = styles.Levels[log.WarnLevel].UnsetForeground()
styles.Levels[log.ErrorLevel] = styles.Levels[log.ErrorLevel].UnsetForeground()
styles.Levels[log.FatalLevel] = styles.Levels[log.FatalLevel].UnsetForeground()

log.SetStyles(styles)
}

Check warning on line 108 in cmd/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/root.go#L99-L108

Added lines #L99 - L108 were not covered by tests
var output io.Writer

switch atmosConfig.Logs.File {
Expand Down Expand Up @@ -194,6 +205,7 @@
RootCmd.PersistentFlags().String("base-path", "", "Base path for Atmos project")
RootCmd.PersistentFlags().StringSlice("config", []string{}, "Paths to configuration files (comma-separated or repeated flag)")
RootCmd.PersistentFlags().StringSlice("config-path", []string{}, "Paths to configuration directories (comma-separated or repeated flag)")
RootCmd.PersistentFlags().Bool("no-color", false, "Disable color output")
// Set custom usage template
err := templates.SetCustomUsageFunc(RootCmd)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions cmd/validate_editorconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,9 @@
cliConfig.Verbose = true
}
}
if !cmd.Flags().Changed("no-color") && !atmosConfig.Validate.EditorConfig.Color {
cliConfig.NoColor = !atmosConfig.Validate.EditorConfig.Color
cliConfig.NoColor = atmosConfig.Settings.Terminal.NoColor
if atmosConfig.Settings.Terminal.NoColor {
cliConfig.NoColor = atmosConfig.Settings.Terminal.NoColor

Check warning on line 121 in cmd/validate_editorconfig.go

View check run for this annotation

Codecov / codecov/patch

cmd/validate_editorconfig.go#L121

Added line #L121 was not covered by tests
}
if !cmd.Flags().Changed("disable-trim-trailing-whitespace") && atmosConfig.Validate.EditorConfig.DisableTrimTrailingWhitespace {
cliConfig.Disable.TrimTrailingWhitespace = atmosConfig.Validate.EditorConfig.DisableTrimTrailingWhitespace
Expand Down Expand Up @@ -192,7 +193,6 @@
cmd.PersistentFlags().BoolVar(&cliConfig.DryRun, "dry-run", false, "Show which files would be checked")
cmd.PersistentFlags().BoolVar(&cliConfig.ShowVersion, "version", false, "Print the version number")
cmd.PersistentFlags().StringVar(&format, "format", "default", "Specify the output format: default, gcc")
cmd.PersistentFlags().BoolVar(&cliConfig.NoColor, "no-color", false, "Don't print colors")
cmd.PersistentFlags().BoolVar(&cliConfig.Disable.TrimTrailingWhitespace, "disable-trim-trailing-whitespace", false, "Disable trailing whitespace check")
cmd.PersistentFlags().BoolVar(&cliConfig.Disable.EndOfLine, "disable-end-of-line", false, "Disable end-of-line check")
cmd.PersistentFlags().BoolVar(&cliConfig.Disable.InsertFinalNewline, "disable-insert-final-newline", false, "Disable final newline check")
Expand Down
5 changes: 5 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@
if v, ok := flagKeyValue["logs-file"]; ok {
atmosConfig.Logs.File = v
}
if flagKeyValue, ok := flagKeyValue["no-color"]; ok || flagKeyValue == "true" {
atmosConfig.Settings.Terminal.NoColor = true

Check warning on line 81 in pkg/config/config.go

View check run for this annotation

Codecov / codecov/patch

pkg/config/config.go#L81

Added line #L81 was not covered by tests
} else if flagKeyValue == "false" {
atmosConfig.Settings.Terminal.NoColor = false
}

Check warning on line 84 in pkg/config/config.go

View check run for this annotation

Codecov / codecov/patch

pkg/config/config.go#L83-L84

Added lines #L83 - L84 were not covered by tests
}

// TODO: This function works well, but we should generally avoid implementing manual flag parsing,
Expand Down
1 change: 0 additions & 1 deletion pkg/config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ var (
Terminal: schema.Terminal{
MaxWidth: templates.GetTerminalWidth(),
Pager: true,
Colors: true,
Unicode: true,
SyntaxHighlighting: schema.SyntaxHighlighting{
Enabled: true,
Expand Down
5 changes: 3 additions & 2 deletions pkg/config/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ func LoadConfig(configAndStacksInfo *schema.ConfigAndStacksInfo) (schema.AtmosCo
}
}
setEnv(v)
// We want the editorconfig color by default to be true
atmosConfig.Validate.EditorConfig.Color = true
// https://gist.github.com/chazcheadle/45bf85b793dea2b71bd05ebaa3c28644
// https://sagikazarmark.hu/blog/decoding-custom-formats-with-viper/
err := v.Unmarshal(&atmosConfig)
Expand All @@ -99,6 +97,8 @@ func setEnv(v *viper.Viper) {
bindEnv(v, "settings.gitlab_token", "GITLAB_TOKEN")
bindEnv(v, "settings.inject_gitlab_token", "ATMOS_INJECT_GITLAB_TOKEN")
bindEnv(v, "settings.atmos_gitlab_token", "ATMOS_GITLAB_TOKEN")

bindEnv(v, "settings.terminal.no_color", "ATMOS_NO_COLOR", "NO_COLOR")
}

func bindEnv(v *viper.Viper, key ...string) {
Expand All @@ -115,6 +115,7 @@ func setDefaultConfiguration(v *viper.Viper) {
v.SetDefault("settings.inject_github_token", true)
v.SetDefault("logs.file", "/dev/stderr")
v.SetDefault("logs.level", "Info")
v.SetDefault("settings.terminal.no_color", false)
}

// loadConfigSources delegates reading configs from each source,
Expand Down
3 changes: 1 addition & 2 deletions pkg/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ type EditorConfig struct {
IgnoreDefaults bool `yaml:"ignore_defaults,omitempty" json:"ignore_defaults,omitempty" mapstructure:"ignore_defaults"`
DryRun bool `yaml:"dry_run,omitempty" json:"dry_run,omitempty" mapstructure:"dry_run"`
Format string `yaml:"format,omitempty" json:"format,omitempty" mapstructure:"format"`
Color bool `yaml:"color,omitempty" json:"color,omitempty" mapstructure:"color"`
ConfigFilePaths []string `yaml:"config_file_paths,omitempty" json:"config_file_paths,omitempty" mapstructure:"config_file_paths"`
Exclude []string `yaml:"exclude,omitempty" json:"exclude,omitempty" mapstructure:"exclude"`
Init bool `yaml:"init,omitempty" json:"init,omitempty" mapstructure:"init"`
Expand All @@ -189,9 +188,9 @@ type EditorConfig struct {
type Terminal struct {
MaxWidth int `yaml:"max_width" json:"max_width" mapstructure:"max_width"`
Pager bool `yaml:"pager" json:"pager" mapstructure:"pager"`
Colors bool `yaml:"colors" json:"colors" mapstructure:"colors"`
Unicode bool `yaml:"unicode" json:"unicode" mapstructure:"unicode"`
SyntaxHighlighting SyntaxHighlighting `yaml:"syntax_highlighting" json:"syntax_highlighting" mapstructure:"syntax_highlighting"`
NoColor bool `yaml:"no_color" json:"no_color" mapstructure:"no_color"`
}

type SyntaxHighlighting struct {
Expand Down
37 changes: 28 additions & 9 deletions pkg/ui/markdown/renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,43 @@

// Renderer is a markdown renderer using Glamour
type Renderer struct {
renderer *glamour.TermRenderer
width uint
profile termenv.Profile
atmosConfig *schema.AtmosConfiguration
renderer *glamour.TermRenderer
width uint
profile termenv.Profile
atmosConfig *schema.AtmosConfiguration
isTTYSupportForStdout func() bool
isTTYSupportForStderr func() bool
}

// NewRenderer creates a new markdown renderer with the given options
func NewRenderer(atmosConfig schema.AtmosConfiguration, opts ...Option) (*Renderer, error) {
r := &Renderer{
width: 80, // default width
profile: termenv.ColorProfile(), // default color profile
width: 80, // default width
profile: termenv.ColorProfile(), // default color profile
isTTYSupportForStdout: term.IsTTYSupportForStdout,
isTTYSupportForStderr: term.IsTTYSupportForStderr,
}

// Apply options
for _, opt := range opts {
opt(r)
}

if atmosConfig.Settings.Terminal.NoColor {
renderer, err := glamour.NewTermRenderer(
glamour.WithAutoStyle(),
glamour.WithWordWrap(int(r.width)),
glamour.WithColorProfile(r.profile),
glamour.WithEmoji(),
)
if err != nil {
return nil, err
}

Check warning on line 48 in pkg/ui/markdown/renderer.go

View check run for this annotation

Codecov / codecov/patch

pkg/ui/markdown/renderer.go#L47-L48

Added lines #L47 - L48 were not covered by tests

r.renderer = renderer
return r, nil
}

// Get default style
style, err := GetDefaultStyle(atmosConfig)
if err != nil {
Expand Down Expand Up @@ -66,7 +85,7 @@
return "", err
}
result := ""
if term.IsTTYSupportForStdout() {
if r.isTTYSupportForStdout() {

Check warning on line 88 in pkg/ui/markdown/renderer.go

View check run for this annotation

Codecov / codecov/patch

pkg/ui/markdown/renderer.go#L88

Added line #L88 was not covered by tests
result, err = out.Render(content)
} else {
// Fallback to ASCII rendering for non-TTY stdout
Expand All @@ -79,7 +98,7 @@
func (r *Renderer) Render(content string) (string, error) {
var rendered string
var err error
if term.IsTTYSupportForStdout() {
if r.isTTYSupportForStdout() {
rendered, err = r.renderer.Render(content)
} else {
// Fallback to ASCII rendering for non-TTY stdout
Expand Down Expand Up @@ -183,7 +202,7 @@

// RenderErrorf renders an error message with specific styling
func (r *Renderer) RenderErrorf(content string, args ...interface{}) (string, error) {
if term.IsTTYSupportForStderr() {
if r.isTTYSupportForStderr() {

Check warning on line 205 in pkg/ui/markdown/renderer.go

View check run for this annotation

Codecov / codecov/patch

pkg/ui/markdown/renderer.go#L205

Added line #L205 was not covered by tests
return r.Render(content)
}
// Fallback to ASCII rendering for non-TTY stderr
Expand Down
53 changes: 53 additions & 0 deletions pkg/ui/markdown/renderer_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package markdown

import (
"testing"

"github.com/cloudposse/atmos/pkg/schema"
"github.com/stretchr/testify/assert"
)

func TestRenderer(t *testing.T) {
tests := []struct {
name string
input string
expected string
atmosConfig schema.AtmosConfiguration
}{
{
name: "Test with no color",
input: "## Hello **world**",
expected: " ## Hello **world**",
atmosConfig: schema.AtmosConfiguration{
Settings: schema.AtmosSettings{
Terminal: schema.Terminal{
NoColor: true,
},
},
},
},
{
name: "Test with color",
input: "## Hello **world**",
expected: "\x1b[;1m\x1b[0m\x1b[;1m\x1b[0m\x1b[;1m## \x1b[0m\x1b[;1mHello \x1b[0m\x1b[;1m**\x1b[0m\x1b[;1mworld\x1b[0m\x1b[;1m**\x1b[0m",
atmosConfig: schema.AtmosConfiguration{
Settings: schema.AtmosSettings{
Terminal: schema.Terminal{
NoColor: false,
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
r, _ := NewRenderer(tt.atmosConfig)
r.isTTYSupportForStdout = func() bool {
return true
}
str, err := r.Render(tt.input)
assert.Contains(t, str, tt.expected)
assert.NoError(t, err)
})
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions tests/snapshots/TestCLICommands_atmos_--help.stdout.golden

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading