From 86c04883a6fc1c55eba1e222d29543fda06063b4 Mon Sep 17 00:00:00 2001 From: Cerebrovinny Date: Tue, 7 Jan 2025 15:34:47 +0000 Subject: [PATCH 01/11] tty highlight colors rebuild --- atmos.yaml | 20 ++- pkg/config/config.go | 19 +++ pkg/schema/schema.go | 25 +++- pkg/utils/highlight_utils.go | 134 ++++++++++++++++++++ pkg/utils/json_utils.go | 16 ++- pkg/utils/yaml_utils.go | 16 ++- website/docs/cli/configuration/terminal.mdx | 117 +++++++++++++++++ 7 files changed, 335 insertions(+), 12 deletions(-) create mode 100644 pkg/utils/highlight_utils.go create mode 100644 website/docs/cli/configuration/terminal.mdx diff --git a/atmos.yaml b/atmos.yaml index 8fffeebba..72d4c1c14 100644 --- a/atmos.yaml +++ b/atmos.yaml @@ -320,11 +320,21 @@ settings: # Terminal settings for displaying content terminal: - max_width: 120 # Maximum width for terminal output - pager: true # Use pager for long output - timestamps: false # Show timestamps in logs - colors: true # Enable colored output - unicode: true # Use unicode characters + max_width: 120 # Maximum width for terminal output + pager: true # Use pager for long output + timestamps: false # Show timestamps in logs + colors: true # Enable colored output + unicode: true # Use unicode characters + + syntax_highlighting: + enabled: true + lexer: yaml # Default lexer for the content + formatter: terminal # Output formatter (e.g., terminal, html) + style: dracula # Highlighting style + pager: true # Enable pager + options: + line_numbers: true # Display line numbers + wrap: false # Wrap long lines # Markdown element styling markdown: diff --git a/pkg/config/config.go b/pkg/config/config.go index 8b552b0e0..f6a2757f7 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -53,6 +53,25 @@ var ( UseEKS: true, }, }, + Settings: schema.AtmosSettings{ + Terminal: schema.Terminal{ + MaxWidth: 180, + Pager: true, + Colors: true, + Unicode: true, + SyntaxHighlighting: schema.SyntaxHighlighting{ + Enabled: true, + Lexer: "yaml", + Formatter: "terminal256", + Style: "monokai", + Pager: true, + Options: schema.HighlightOptions{ + LineNumbers: true, + Wrap: true, + }, + }, + }, + }, Workflows: schema.Workflows{ BasePath: "stacks/workflows", }, diff --git a/pkg/schema/schema.go b/pkg/schema/schema.go index 7347fe5ec..33dd730cd 100644 --- a/pkg/schema/schema.go +++ b/pkg/schema/schema.go @@ -38,11 +38,26 @@ type AtmosConfiguration struct { } type Terminal struct { - MaxWidth int `yaml:"max_width" json:"max_width" mapstructure:"max_width"` - Pager bool `yaml:"pager" json:"pager" mapstructure:"pager"` - Timestamps bool `yaml:"timestamps" json:"timestamps" mapstructure:"timestamps"` - Colors bool `yaml:"colors" json:"colors" mapstructure:"colors"` - Unicode bool `yaml:"unicode" json:"unicode" mapstructure:"unicode"` + MaxWidth int `yaml:"max_width" json:"max_width" mapstructure:"max_width"` + Pager bool `yaml:"pager" json:"pager" mapstructure:"pager"` + Timestamps bool `yaml:"timestamps" json:"timestamps" mapstructure:"timestamps"` + 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"` +} + +type SyntaxHighlighting struct { + Enabled bool `yaml:"enabled" json:"enabled" mapstructure:"enabled"` + Lexer string `yaml:"lexer" json:"lexer" mapstructure:"lexer"` + Formatter string `yaml:"formatter" json:"formatter" mapstructure:"formatter"` + Style string `yaml:"style" json:"style" mapstructure:"style"` + Pager bool `yaml:"pager" json:"pager" mapstructure:"pager"` + Options HighlightOptions `yaml:"options" json:"options" mapstructure:"options"` +} + +type HighlightOptions struct { + LineNumbers bool `yaml:"line_numbers" json:"line_numbers" mapstructure:"line_numbers"` + Wrap bool `yaml:"wrap" json:"wrap" mapstructure:"wrap"` } type AtmosSettings struct { diff --git a/pkg/utils/highlight_utils.go b/pkg/utils/highlight_utils.go new file mode 100644 index 000000000..30d7aa82e --- /dev/null +++ b/pkg/utils/highlight_utils.go @@ -0,0 +1,134 @@ +package utils + +import ( + "bytes" + "io" + "os" + + "github.com/alecthomas/chroma" + "github.com/alecthomas/chroma/formatters" + "github.com/alecthomas/chroma/lexers" + "github.com/alecthomas/chroma/quick" + "github.com/alecthomas/chroma/styles" + "github.com/cloudposse/atmos/pkg/schema" + "golang.org/x/term" +) + +// DefaultHighlightSettings returns the default syntax highlighting settings +func DefaultHighlightSettings() *schema.SyntaxHighlighting { + return &schema.SyntaxHighlighting{ + Enabled: true, + Lexer: "yaml", + Formatter: "terminal", + Style: "dracula", + Options: schema.HighlightOptions{ + LineNumbers: false, + Wrap: false, + }, + } +} + +// GetHighlightSettings returns the syntax highlighting settings from the config or defaults +func GetHighlightSettings(config schema.AtmosConfiguration) *schema.SyntaxHighlighting { + defaults := DefaultHighlightSettings() + if config.Settings.Terminal.SyntaxHighlighting == (schema.SyntaxHighlighting{}) { + return defaults + } + settings := &config.Settings.Terminal.SyntaxHighlighting + // Apply defaults for any unset fields + if !settings.Enabled { + settings.Enabled = defaults.Enabled + } + if settings.Lexer == "" { + settings.Lexer = defaults.Lexer + } + if settings.Formatter == "" { + settings.Formatter = defaults.Formatter + } + if settings.Style == "" { + settings.Style = defaults.Style + } + if settings.Options == (schema.HighlightOptions{}) { + settings.Options = defaults.Options + } + return settings +} + +// HighlightCode highlights the given code using chroma with the specified lexer and style +func HighlightCode(code string, lexerName string, style string) (string, error) { + if !term.IsTerminal(int(os.Stdout.Fd())) { + return code, nil + } + var buf bytes.Buffer + err := quick.Highlight(&buf, code, lexerName, "terminal", style) + if err != nil { + return code, err + } + return buf.String(), nil +} + +// HighlightCodeWithConfig highlights the given code using the provided configuration +func HighlightCodeWithConfig(code string, config schema.AtmosConfiguration) (string, error) { + if !term.IsTerminal(int(os.Stdout.Fd())) { + return code, nil + } + settings := GetHighlightSettings(config) + if !settings.Enabled { + return code, nil + } + // Get lexer + lexer := lexers.Get(settings.Lexer) + if lexer == nil { + lexer = lexers.Fallback + } + // Get style + s := styles.Get(settings.Style) + if s == nil { + s = styles.Fallback + } + // Get formatter + var formatter chroma.Formatter + if settings.Options.LineNumbers { + formatter = formatters.TTY256 + } else { + formatter = formatters.Get(settings.Formatter) + if formatter == nil { + formatter = formatters.Fallback + } + } + // Create buffer for output + var buf bytes.Buffer + // Format the code + iterator, err := lexer.Tokenise(nil, code) + if err != nil { + return code, err + } + err = formatter.Format(&buf, s, iterator) + if err != nil { + return code, err + } + return buf.String(), nil +} + +// HighlightWriter returns an io.Writer that highlights code written to it +type HighlightWriter struct { + config schema.AtmosConfiguration + writer io.Writer +} + +// NewHighlightWriter creates a new HighlightWriter +func NewHighlightWriter(w io.Writer, config schema.AtmosConfiguration) *HighlightWriter { + return &HighlightWriter{ + config: config, + writer: w, + } +} + +// Write implements io.Writer +func (h *HighlightWriter) Write(p []byte) (n int, err error) { + highlighted, err := HighlightCodeWithConfig(string(p), h.config) + if err != nil { + return 0, err + } + return h.writer.Write([]byte(highlighted)) +} diff --git a/pkg/utils/json_utils.go b/pkg/utils/json_utils.go index 9107415a6..be7c9869a 100644 --- a/pkg/utils/json_utils.go +++ b/pkg/utils/json_utils.go @@ -24,7 +24,21 @@ func PrintAsJSON(data any) error { return err } - PrintMessage(prettyJSON.String()) + // Get the Atmos configuration + var atmosConfig schema.AtmosConfiguration + switch v := data.(type) { + case schema.AtmosConfiguration: + atmosConfig = v + case *schema.AtmosConfiguration: + atmosConfig = *v + } + highlighted, err := HighlightCodeWithConfig(prettyJSON.String(), atmosConfig) + if err != nil { + // Fallback to plain text if highlighting fails + PrintMessage(prettyJSON.String()) + return nil + } + PrintMessage(highlighted) return nil } diff --git a/pkg/utils/yaml_utils.go b/pkg/utils/yaml_utils.go index e27c6401c..986620645 100644 --- a/pkg/utils/yaml_utils.go +++ b/pkg/utils/yaml_utils.go @@ -31,7 +31,21 @@ func PrintAsYAML(data any) error { if err != nil { return err } - PrintMessage(y) + + var atmosConfig schema.AtmosConfiguration + switch v := data.(type) { + case schema.AtmosConfiguration: + atmosConfig = v + case *schema.AtmosConfiguration: + atmosConfig = *v + } + highlighted, err := HighlightCodeWithConfig(y, atmosConfig) + if err != nil { + // Fallback to plain text if highlighting fails + PrintMessage(y) + return nil + } + PrintMessage(highlighted) return nil } diff --git a/website/docs/cli/configuration/terminal.mdx b/website/docs/cli/configuration/terminal.mdx new file mode 100644 index 000000000..df2708400 --- /dev/null +++ b/website/docs/cli/configuration/terminal.mdx @@ -0,0 +1,117 @@ +--- +title: Terminal Settings +sidebar_position: 4 +description: Configure terminal output settings including syntax highlighting +--- + +import Intro from '@site/src/components/Intro'; +import KeyPoints from '@site/src/components/KeyPoints'; +import Note from '@site/src/components/Note'; +import File from '@site/src/components/File'; + + +Atmos provides configurable terminal settings that allow you to customize the output appearance, including syntax highlighting for YAML and JSON outputs. These settings can be configured in your `atmos.yaml` configuration file. + + +- Configure syntax highlighting for terminal output +- Customize color schemes and formatting options +- Control output pagination and line wrapping +- Set display preferences for different output formats + +## Syntax Highlighting +You can customize the syntax highlighting behavior for terminal output using the following settings in your `atmos.yaml`: + +```yaml +settings: + terminal: + syntax_highlighting: + enabled: true # Enable/disable syntax highlighting + lexer: yaml # Lexer to use (yaml or json) + formatter: terminal # Output formatter + style: dracula # Color scheme to use; see list of supported themes bellow + pager: false # Whether to use a pager for output + options: + line_numbers: false # Show line numbers + wrap: false # Wrap long lines +``` + +### Configuration Options +
+
`enabled`
+
Enable or disable syntax highlighting (default: `true`)
+ +
`lexer`
+
+ Specify the lexer to use for syntax highlighting: +
+
`yaml`
+
For YAML output
+
`json`
+
For JSON output
+
+
+ +
`formatter`
+
Output formatter (default: `terminal`)
+ +
`style`
+
+ Color scheme for syntax highlighting. Available options include: +
    +
  • `vim`
  • +
  • `monokai`
  • +
  • `github`
  • +
  • `dracula`
  • +
  • And many other standard styles
  • +
+
+ +
`pager`
+
Whether to use a pager for long output (default: `false`)
+ +
`options`
+
+ Additional formatting options: +
+
`line_numbers`
+
Show line numbers in output (default: `false`)
+
`wrap`
+
Wrap long lines (default: `false`)
+
+
+
+### Example Usage +The syntax highlighting is automatically applied when using commands that output YAML or JSON, such as: +```bash +# Display config in YAML format with syntax highlighting +atmos describe config -f yaml +# Display config in JSON format with syntax highlighting +atmos describe config +``` + +When the output is piped to another command, syntax highlighting is automatically disabled to ensure compatibility: +```bash +# Syntax highlighting is disabled when piping +atmos describe config | grep base_path +``` + +## Default Settings +If not specified in your `atmos.yaml`, Atmos uses these default settings: + +```yaml +settings: + terminal: + syntax_highlighting: + enabled: true + lexer: yaml + formatter: terminal + style: dracula + pager: false + options: + line_numbers: false + wrap: false +``` + +You can override any of these settings in your [Atmos CLI configuration](/cli/configuration) file. +## Supported Themes +Atmos supports a wide range of themes for syntax highlighting. You can find the full list of supported themes [here](https://xyproto.github.io/splash/docs/). \ No newline at end of file From f3cb07e66bb6b136bd8140e3fb650203626896ef Mon Sep 17 00:00:00 2001 From: Cerebrovinny Date: Tue, 7 Jan 2025 16:02:45 +0000 Subject: [PATCH 02/11] lexer fixes and improvements --- atmos.yaml | 3 +-- internal/tui/templates/templater.go | 6 +++--- pkg/config/config.go | 11 ++++++----- pkg/utils/highlight_utils.go | 23 +++++++++++++++++------ 4 files changed, 27 insertions(+), 16 deletions(-) diff --git a/atmos.yaml b/atmos.yaml index 72d4c1c14..d6a6dd788 100644 --- a/atmos.yaml +++ b/atmos.yaml @@ -325,10 +325,9 @@ settings: timestamps: false # Show timestamps in logs colors: true # Enable colored output unicode: true # Use unicode characters - + syntax_highlighting: enabled: true - lexer: yaml # Default lexer for the content formatter: terminal # Output formatter (e.g., terminal, html) style: dracula # Highlighting style pager: true # Enable pager diff --git a/internal/tui/templates/templater.go b/internal/tui/templates/templater.go index c4539a6ea..468f71329 100644 --- a/internal/tui/templates/templater.go +++ b/internal/tui/templates/templater.go @@ -137,8 +137,8 @@ func SetCustomUsageFunc(cmd *cobra.Command) error { return nil } -// getTerminalWidth returns the width of the terminal, defaulting to 80 if it cannot be determined -func getTerminalWidth() int { +// GetTerminalWidth returns the width of the terminal, defaulting to 80 if it cannot be determined +func GetTerminalWidth() int { defaultWidth := 80 screenWidth := defaultWidth @@ -156,7 +156,7 @@ func getTerminalWidth() int { // WrappedFlagUsages formats the flag usage string to fit within the terminal width func WrappedFlagUsages(f *pflag.FlagSet) string { var builder strings.Builder - width := getTerminalWidth() + width := GetTerminalWidth() printer, err := NewHelpFlagPrinter(&builder, uint(width), f) if err != nil { // If we can't create the printer, return empty string diff --git a/pkg/config/config.go b/pkg/config/config.go index f6a2757f7..a2de6cd5d 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -12,6 +12,7 @@ import ( "github.com/pkg/errors" "github.com/spf13/viper" + "github.com/cloudposse/atmos/internal/tui/templates" "github.com/cloudposse/atmos/pkg/schema" "github.com/cloudposse/atmos/pkg/ui/theme" u "github.com/cloudposse/atmos/pkg/utils" @@ -54,20 +55,20 @@ var ( }, }, Settings: schema.AtmosSettings{ + ListMergeStrategy: "replace", Terminal: schema.Terminal{ - MaxWidth: 180, + MaxWidth: templates.GetTerminalWidth(), Pager: true, Colors: true, Unicode: true, SyntaxHighlighting: schema.SyntaxHighlighting{ Enabled: true, - Lexer: "yaml", - Formatter: "terminal256", - Style: "monokai", + Formatter: "terminal", + Style: "dracula", Pager: true, Options: schema.HighlightOptions{ LineNumbers: true, - Wrap: true, + Wrap: false, }, }, }, diff --git a/pkg/utils/highlight_utils.go b/pkg/utils/highlight_utils.go index 30d7aa82e..05c16a384 100644 --- a/pkg/utils/highlight_utils.go +++ b/pkg/utils/highlight_utils.go @@ -4,12 +4,14 @@ import ( "bytes" "io" "os" + "strings" "github.com/alecthomas/chroma" "github.com/alecthomas/chroma/formatters" "github.com/alecthomas/chroma/lexers" "github.com/alecthomas/chroma/quick" "github.com/alecthomas/chroma/styles" + "github.com/cloudposse/atmos/internal/tui/templates" "github.com/cloudposse/atmos/pkg/schema" "golang.org/x/term" ) @@ -18,11 +20,11 @@ import ( func DefaultHighlightSettings() *schema.SyntaxHighlighting { return &schema.SyntaxHighlighting{ Enabled: true, - Lexer: "yaml", Formatter: "terminal", Style: "dracula", + Pager: true, Options: schema.HighlightOptions{ - LineNumbers: false, + LineNumbers: true, Wrap: false, }, } @@ -39,9 +41,6 @@ func GetHighlightSettings(config schema.AtmosConfiguration) *schema.SyntaxHighli if !settings.Enabled { settings.Enabled = defaults.Enabled } - if settings.Lexer == "" { - settings.Lexer = defaults.Lexer - } if settings.Formatter == "" { settings.Formatter = defaults.Formatter } @@ -76,8 +75,20 @@ func HighlightCodeWithConfig(code string, config schema.AtmosConfiguration) (str if !settings.Enabled { return code, nil } + + // Get terminal width + config.Settings.Terminal.MaxWidth = templates.GetTerminalWidth() + + // Determine lexer based on content format + var lexerName string + if strings.HasPrefix(strings.TrimSpace(code), "{") { + lexerName = "json" + } else { + lexerName = "yaml" + } + // Get lexer - lexer := lexers.Get(settings.Lexer) + lexer := lexers.Get(lexerName) if lexer == nil { lexer = lexers.Fallback } From 4b6adbb93e4cfab172cb8bce592e0ddadeb338f3 Mon Sep 17 00:00:00 2001 From: Cerebrovinny Date: Tue, 7 Jan 2025 21:56:56 +0000 Subject: [PATCH 03/11] added general fixes and refactoring --- cmd/docs.go | 2 +- pkg/schema/schema.go | 4 +- pkg/utils/config_utils.go | 17 +++++++ pkg/utils/highlight_utils.go | 39 ++++++++++++++-- pkg/utils/json_utils.go | 9 +--- pkg/utils/yaml_utils.go | 8 +--- website/docs/cli/configuration/terminal.mdx | 49 ++++++++++++++++----- 7 files changed, 96 insertions(+), 32 deletions(-) create mode 100644 pkg/utils/config_utils.go diff --git a/cmd/docs.go b/cmd/docs.go index 25ded076c..f9d3e4bc9 100644 --- a/cmd/docs.go +++ b/cmd/docs.go @@ -101,7 +101,7 @@ var docsCmd = &cobra.Command{ u.LogErrorAndExit(schema.AtmosConfiguration{}, err) } - usePager := atmosConfig.Settings.Terminal.Pager + usePager := atmosConfig.Settings.Terminal.UsePager if !usePager && atmosConfig.Settings.Docs.Pagination { usePager = atmosConfig.Settings.Docs.Pagination u.LogWarning(atmosConfig, "'settings.docs.pagination' is deprecated and will be removed in a future version. Please use 'settings.terminal.pager' instead") diff --git a/pkg/schema/schema.go b/pkg/schema/schema.go index 33dd730cd..9150ff4c0 100644 --- a/pkg/schema/schema.go +++ b/pkg/schema/schema.go @@ -39,7 +39,7 @@ type AtmosConfiguration struct { type Terminal struct { MaxWidth int `yaml:"max_width" json:"max_width" mapstructure:"max_width"` - Pager bool `yaml:"pager" json:"pager" mapstructure:"pager"` + UsePager bool `yaml:"pager" json:"pager" mapstructure:"pager"` Timestamps bool `yaml:"timestamps" json:"timestamps" mapstructure:"timestamps"` Colors bool `yaml:"colors" json:"colors" mapstructure:"colors"` Unicode bool `yaml:"unicode" json:"unicode" mapstructure:"unicode"` @@ -51,7 +51,7 @@ type SyntaxHighlighting struct { Lexer string `yaml:"lexer" json:"lexer" mapstructure:"lexer"` Formatter string `yaml:"formatter" json:"formatter" mapstructure:"formatter"` Style string `yaml:"style" json:"style" mapstructure:"style"` - Pager bool `yaml:"pager" json:"pager" mapstructure:"pager"` + UsePager bool `yaml:"pager" json:"pager" mapstructure:"pager"` Options HighlightOptions `yaml:"options" json:"options" mapstructure:"options"` } diff --git a/pkg/utils/config_utils.go b/pkg/utils/config_utils.go new file mode 100644 index 000000000..1c6c36101 --- /dev/null +++ b/pkg/utils/config_utils.go @@ -0,0 +1,17 @@ +package utils + +import "github.com/cloudposse/atmos/pkg/schema" + +// ExtractAtmosConfig extracts the Atmos configuration from any data type. +// It handles both direct AtmosConfiguration instances and pointers to AtmosConfiguration. +// If the data is neither, it returns an empty configuration. +func ExtractAtmosConfig(data any) schema.AtmosConfiguration { + switch v := data.(type) { + case schema.AtmosConfiguration: + return v + case *schema.AtmosConfiguration: + return *v + default: + return schema.AtmosConfiguration{} + } +} diff --git a/pkg/utils/highlight_utils.go b/pkg/utils/highlight_utils.go index 05c16a384..68607c026 100644 --- a/pkg/utils/highlight_utils.go +++ b/pkg/utils/highlight_utils.go @@ -6,6 +6,8 @@ import ( "os" "strings" + "encoding/json" + "github.com/alecthomas/chroma" "github.com/alecthomas/chroma/formatters" "github.com/alecthomas/chroma/lexers" @@ -22,7 +24,7 @@ func DefaultHighlightSettings() *schema.SyntaxHighlighting { Enabled: true, Formatter: "terminal", Style: "dracula", - Pager: true, + UsePager: true, Options: schema.HighlightOptions{ LineNumbers: true, Wrap: false, @@ -81,10 +83,24 @@ func HighlightCodeWithConfig(code string, config schema.AtmosConfiguration) (str // Determine lexer based on content format var lexerName string - if strings.HasPrefix(strings.TrimSpace(code), "{") { + trimmed := strings.TrimSpace(code) + + // Try to parse as JSON first + if json.Valid([]byte(trimmed)) { lexerName = "json" } else { - lexerName = "yaml" + // Check for common YAML indicators + // 1. Contains key-value pairs with colons + // 2. Does not start with a curly brace (which could indicate malformed JSON) + // 3. Contains indentation or list markers + if (strings.Contains(trimmed, ":") && !strings.HasPrefix(trimmed, "{")) || + strings.Contains(trimmed, "\n ") || + strings.Contains(trimmed, "\n- ") { + lexerName = "yaml" + } else { + // Fallback to plaintext if format is unclear + lexerName = "plaintext" + } } // Get lexer @@ -136,10 +152,25 @@ func NewHighlightWriter(w io.Writer, config schema.AtmosConfiguration) *Highligh } // Write implements io.Writer +// The returned byte count n is the length of p regardless of whether the highlighting +// process changes the actual number of bytes written to the underlying writer. +// This maintains compatibility with the io.Writer interface contract while still +// providing syntax highlighting functionality. func (h *HighlightWriter) Write(p []byte) (n int, err error) { highlighted, err := HighlightCodeWithConfig(string(p), h.config) if err != nil { return 0, err } - return h.writer.Write([]byte(highlighted)) + + // Write the highlighted content, ignoring the actual number of bytes written + // since we'll return the original input length + _, err = h.writer.Write([]byte(highlighted)) + if err != nil { + // If there's an error, we can't be sure how many bytes were actually written + return 0, err + } + + // Return the original length of p as required by io.Writer interface + // This ensures that the caller knows all bytes from p were processed + return len(p), nil } diff --git a/pkg/utils/json_utils.go b/pkg/utils/json_utils.go index be7c9869a..86ae7cba5 100644 --- a/pkg/utils/json_utils.go +++ b/pkg/utils/json_utils.go @@ -24,14 +24,7 @@ func PrintAsJSON(data any) error { return err } - // Get the Atmos configuration - var atmosConfig schema.AtmosConfiguration - switch v := data.(type) { - case schema.AtmosConfiguration: - atmosConfig = v - case *schema.AtmosConfiguration: - atmosConfig = *v - } + atmosConfig := ExtractAtmosConfig(data) highlighted, err := HighlightCodeWithConfig(prettyJSON.String(), atmosConfig) if err != nil { // Fallback to plain text if highlighting fails diff --git a/pkg/utils/yaml_utils.go b/pkg/utils/yaml_utils.go index 986620645..a7af8a2c9 100644 --- a/pkg/utils/yaml_utils.go +++ b/pkg/utils/yaml_utils.go @@ -32,13 +32,7 @@ func PrintAsYAML(data any) error { return err } - var atmosConfig schema.AtmosConfiguration - switch v := data.(type) { - case schema.AtmosConfiguration: - atmosConfig = v - case *schema.AtmosConfiguration: - atmosConfig = *v - } + atmosConfig := ExtractAtmosConfig(data) highlighted, err := HighlightCodeWithConfig(y, atmosConfig) if err != nil { // Fallback to plain text if highlighting fails diff --git a/website/docs/cli/configuration/terminal.mdx b/website/docs/cli/configuration/terminal.mdx index df2708400..a79cb346a 100644 --- a/website/docs/cli/configuration/terminal.mdx +++ b/website/docs/cli/configuration/terminal.mdx @@ -18,9 +18,24 @@ Atmos provides configurable terminal settings that allow you to customize the ou - Control output pagination and line wrapping - Set display preferences for different output formats +## General Terminal Settings + +Configure general terminal behavior: + +```yaml +settings: + terminal: + max_width: 120 # Maximum width for terminal output + use_pager: true # Whether to use a pager (like 'less') for long output + timestamps: false # Show timestamps in output + colors: true # Enable colored output + unicode: true # Use Unicode characters in output +``` + ## Syntax Highlighting -You can customize the syntax highlighting behavior for terminal output using the following settings in your `atmos.yaml`: - + +You can customize the syntax highlighting behavior for terminal output using the following settings: + ```yaml settings: terminal: @@ -28,14 +43,15 @@ settings: enabled: true # Enable/disable syntax highlighting lexer: yaml # Lexer to use (yaml or json) formatter: terminal # Output formatter - style: dracula # Color scheme to use; see list of supported themes bellow - pager: false # Whether to use a pager for output + style: dracula # Color scheme to use + use_pager: false # Whether to use a pager for highlighted output options: line_numbers: false # Show line numbers wrap: false # Wrap long lines ``` - + ### Configuration Options +
`enabled`
Enable or disable syntax highlighting (default: `true`)
@@ -66,8 +82,8 @@ settings: -
`pager`
-
Whether to use a pager for long output (default: `false`)
+
`use_pager`
+
Whether to use a pager specifically for syntax-highlighted output (default: `false`)
`options`
@@ -80,14 +96,18 @@ settings:
+ ### Example Usage + The syntax highlighting is automatically applied when using commands that output YAML or JSON, such as: + ```bash # Display config in YAML format with syntax highlighting atmos describe config -f yaml # Display config in JSON format with syntax highlighting atmos describe config ``` + When the output is piped to another command, syntax highlighting is automatically disabled to ensure compatibility: ```bash @@ -95,23 +115,32 @@ When the output is piped to another command, syntax highlighting is automaticall atmos describe config | grep base_path ``` + ## Default Settings + If not specified in your `atmos.yaml`, Atmos uses these default settings: - + ```yaml settings: terminal: + max_width: 120 + use_pager: false + timestamps: false + colors: true + unicode: true syntax_highlighting: enabled: true lexer: yaml formatter: terminal style: dracula - pager: false + use_pager: false options: line_numbers: false wrap: false ``` - + You can override any of these settings in your [Atmos CLI configuration](/cli/configuration) file. + ## Supported Themes + Atmos supports a wide range of themes for syntax highlighting. You can find the full list of supported themes [here](https://xyproto.github.io/splash/docs/). \ No newline at end of file From 737cadfc38da84cfc43548b9b758c59b92a79b75 Mon Sep 17 00:00:00 2001 From: Cerebrovinny Date: Tue, 7 Jan 2025 22:06:15 +0000 Subject: [PATCH 04/11] flag detection --- pkg/config/config.go | 4 +-- pkg/utils/highlight_utils.go | 50 ++++++++++++++++++++++-------------- 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index a2de6cd5d..fb442441c 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -58,14 +58,14 @@ var ( ListMergeStrategy: "replace", Terminal: schema.Terminal{ MaxWidth: templates.GetTerminalWidth(), - Pager: true, + UsePager: true, Colors: true, Unicode: true, SyntaxHighlighting: schema.SyntaxHighlighting{ Enabled: true, Formatter: "terminal", Style: "dracula", - Pager: true, + UsePager: true, Options: schema.HighlightOptions{ LineNumbers: true, Wrap: false, diff --git a/pkg/utils/highlight_utils.go b/pkg/utils/highlight_utils.go index 68607c026..651b81e97 100644 --- a/pkg/utils/highlight_utils.go +++ b/pkg/utils/highlight_utils.go @@ -69,7 +69,7 @@ func HighlightCode(code string, lexerName string, style string) (string, error) } // HighlightCodeWithConfig highlights the given code using the provided configuration -func HighlightCodeWithConfig(code string, config schema.AtmosConfiguration) (string, error) { +func HighlightCodeWithConfig(code string, config schema.AtmosConfiguration, format ...string) (string, error) { if !term.IsTerminal(int(os.Stdout.Fd())) { return code, nil } @@ -81,25 +81,31 @@ func HighlightCodeWithConfig(code string, config schema.AtmosConfiguration) (str // Get terminal width config.Settings.Terminal.MaxWidth = templates.GetTerminalWidth() - // Determine lexer based on content format + // Determine lexer based on format flag or content format var lexerName string - trimmed := strings.TrimSpace(code) - - // Try to parse as JSON first - if json.Valid([]byte(trimmed)) { - lexerName = "json" + if len(format) > 0 && format[0] != "" { + // Use format flag if provided + lexerName = strings.ToLower(format[0]) } else { - // Check for common YAML indicators - // 1. Contains key-value pairs with colons - // 2. Does not start with a curly brace (which could indicate malformed JSON) - // 3. Contains indentation or list markers - if (strings.Contains(trimmed, ":") && !strings.HasPrefix(trimmed, "{")) || - strings.Contains(trimmed, "\n ") || - strings.Contains(trimmed, "\n- ") { - lexerName = "yaml" + // This is just a fallback + trimmed := strings.TrimSpace(code) + + // Try to parse as JSON first + if json.Valid([]byte(trimmed)) { + lexerName = "json" } else { - // Fallback to plaintext if format is unclear - lexerName = "plaintext" + // Check for common YAML indicators + // 1. Contains key-value pairs with colons + // 2. Does not start with a curly brace (which could indicate malformed JSON) + // 3. Contains indentation or list markers + if (strings.Contains(trimmed, ":") && !strings.HasPrefix(trimmed, "{")) || + strings.Contains(trimmed, "\n ") || + strings.Contains(trimmed, "\n- ") { + lexerName = "yaml" + } else { + // Fallback to plaintext if format is unclear + lexerName = "plaintext" + } } } @@ -141,13 +147,19 @@ func HighlightCodeWithConfig(code string, config schema.AtmosConfiguration) (str type HighlightWriter struct { config schema.AtmosConfiguration writer io.Writer + format string } // NewHighlightWriter creates a new HighlightWriter -func NewHighlightWriter(w io.Writer, config schema.AtmosConfiguration) *HighlightWriter { +func NewHighlightWriter(w io.Writer, config schema.AtmosConfiguration, format ...string) *HighlightWriter { + var f string + if len(format) > 0 { + f = format[0] + } return &HighlightWriter{ config: config, writer: w, + format: f, } } @@ -157,7 +169,7 @@ func NewHighlightWriter(w io.Writer, config schema.AtmosConfiguration) *Highligh // This maintains compatibility with the io.Writer interface contract while still // providing syntax highlighting functionality. func (h *HighlightWriter) Write(p []byte) (n int, err error) { - highlighted, err := HighlightCodeWithConfig(string(p), h.config) + highlighted, err := HighlightCodeWithConfig(string(p), h.config, h.format) if err != nil { return 0, err } From 04a61a9e1a0b416ba977322d0c1713710fff2338 Mon Sep 17 00:00:00 2001 From: Cerebrovinny Date: Thu, 9 Jan 2025 07:43:47 +0000 Subject: [PATCH 05/11] updates mdx --- website/docs/cli/configuration/terminal.mdx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/website/docs/cli/configuration/terminal.mdx b/website/docs/cli/configuration/terminal.mdx index a79cb346a..e126c277f 100644 --- a/website/docs/cli/configuration/terminal.mdx +++ b/website/docs/cli/configuration/terminal.mdx @@ -25,9 +25,9 @@ Configure general terminal behavior: ```yaml settings: terminal: - max_width: 120 # Maximum width for terminal output - use_pager: true # Whether to use a pager (like 'less') for long output - timestamps: false # Show timestamps in output + max_width: 120 # Maximum width for terminal output + use_pager: true # Whether to use a pager (like 'less') for long output + timestamps: false # Show timestamps in output colors: true # Enable colored output unicode: true # Use Unicode characters in output ``` @@ -78,8 +78,9 @@ settings:
  • `monokai`
  • `github`
  • `dracula`
  • -
  • And many other standard styles
  • +
  • ...and many other standard themes
  • + You can find the full list of supported themes [here](https://xyproto.github.io/splash/docs/).
    `use_pager`
    From c75bcf82b3bf5941dea702e8b76be13cf8030853 Mon Sep 17 00:00:00 2001 From: Cerebrovinny Date: Thu, 9 Jan 2025 07:44:30 +0000 Subject: [PATCH 06/11] updates mdx --- website/docs/cli/configuration/terminal.mdx | 1 + 1 file changed, 1 insertion(+) diff --git a/website/docs/cli/configuration/terminal.mdx b/website/docs/cli/configuration/terminal.mdx index e126c277f..22c368efc 100644 --- a/website/docs/cli/configuration/terminal.mdx +++ b/website/docs/cli/configuration/terminal.mdx @@ -12,6 +12,7 @@ import File from '@site/src/components/File'; Atmos provides configurable terminal settings that allow you to customize the output appearance, including syntax highlighting for YAML and JSON outputs. These settings can be configured in your `atmos.yaml` configuration file. + - Configure syntax highlighting for terminal output - Customize color schemes and formatting options From b9ad8e1328d5f27f7908bfed565fb6a4798b1092 Mon Sep 17 00:00:00 2001 From: Cerebrovinny Date: Thu, 9 Jan 2025 08:31:37 +0000 Subject: [PATCH 07/11] update theme and docs --- pkg/config/config.go | 2 +- pkg/schema/schema.go | 2 +- pkg/utils/highlight_utils.go | 14 +++--- website/docs/cli/configuration/terminal.mdx | 53 ++++----------------- 4 files changed, 17 insertions(+), 54 deletions(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index fb442441c..cfa87ea0d 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -64,7 +64,7 @@ var ( SyntaxHighlighting: schema.SyntaxHighlighting{ Enabled: true, Formatter: "terminal", - Style: "dracula", + Theme: "dracula", UsePager: true, Options: schema.HighlightOptions{ LineNumbers: true, diff --git a/pkg/schema/schema.go b/pkg/schema/schema.go index 9150ff4c0..3a2d61d0b 100644 --- a/pkg/schema/schema.go +++ b/pkg/schema/schema.go @@ -50,7 +50,7 @@ type SyntaxHighlighting struct { Enabled bool `yaml:"enabled" json:"enabled" mapstructure:"enabled"` Lexer string `yaml:"lexer" json:"lexer" mapstructure:"lexer"` Formatter string `yaml:"formatter" json:"formatter" mapstructure:"formatter"` - Style string `yaml:"style" json:"style" mapstructure:"style"` + Theme string `yaml:"theme" json:"theme" mapstructure:"theme"` UsePager bool `yaml:"pager" json:"pager" mapstructure:"pager"` Options HighlightOptions `yaml:"options" json:"options" mapstructure:"options"` } diff --git a/pkg/utils/highlight_utils.go b/pkg/utils/highlight_utils.go index 651b81e97..0ced05a2f 100644 --- a/pkg/utils/highlight_utils.go +++ b/pkg/utils/highlight_utils.go @@ -23,7 +23,7 @@ func DefaultHighlightSettings() *schema.SyntaxHighlighting { return &schema.SyntaxHighlighting{ Enabled: true, Formatter: "terminal", - Style: "dracula", + Theme: "dracula", UsePager: true, Options: schema.HighlightOptions{ LineNumbers: true, @@ -46,8 +46,8 @@ func GetHighlightSettings(config schema.AtmosConfiguration) *schema.SyntaxHighli if settings.Formatter == "" { settings.Formatter = defaults.Formatter } - if settings.Style == "" { - settings.Style = defaults.Style + if settings.Theme == "" { + settings.Theme = defaults.Theme } if settings.Options == (schema.HighlightOptions{}) { settings.Options = defaults.Options @@ -55,13 +55,13 @@ func GetHighlightSettings(config schema.AtmosConfiguration) *schema.SyntaxHighli return settings } -// HighlightCode highlights the given code using chroma with the specified lexer and style -func HighlightCode(code string, lexerName string, style string) (string, error) { +// HighlightCode highlights the given code using chroma with the specified lexer and theme +func HighlightCode(code string, lexerName string, theme string) (string, error) { if !term.IsTerminal(int(os.Stdout.Fd())) { return code, nil } var buf bytes.Buffer - err := quick.Highlight(&buf, code, lexerName, "terminal", style) + err := quick.Highlight(&buf, code, lexerName, "terminal", theme) if err != nil { return code, err } @@ -115,7 +115,7 @@ func HighlightCodeWithConfig(code string, config schema.AtmosConfiguration, form lexer = lexers.Fallback } // Get style - s := styles.Get(settings.Style) + s := styles.Get(settings.Theme) if s == nil { s = styles.Fallback } diff --git a/website/docs/cli/configuration/terminal.mdx b/website/docs/cli/configuration/terminal.mdx index 22c368efc..fe56aae64 100644 --- a/website/docs/cli/configuration/terminal.mdx +++ b/website/docs/cli/configuration/terminal.mdx @@ -21,16 +21,16 @@ Atmos provides configurable terminal settings that allow you to customize the ou ## General Terminal Settings -Configure general terminal behavior: +Configure general terminal behavior. These are also the default settings if not specified in your `atmos.yaml`: ```yaml settings: terminal: - max_width: 120 # Maximum width for terminal output - use_pager: true # Whether to use a pager (like 'less') for long output - timestamps: false # Show timestamps in output - colors: true # Enable colored output - unicode: true # Use Unicode characters in output + max_width: 120 # Maximum width for terminal output + use_pager: false # Whether to use a pager (like 'less') for long output + timestamps: false # Show timestamps in output + colors: true # Enable colored output + unicode: true # Use Unicode characters in output ``` ## Syntax Highlighting @@ -42,9 +42,8 @@ settings: terminal: syntax_highlighting: enabled: true # Enable/disable syntax highlighting - lexer: yaml # Lexer to use (yaml or json) formatter: terminal # Output formatter - style: dracula # Color scheme to use + theme: dracula # Color scheme to use use_pager: false # Whether to use a pager for highlighted output options: line_numbers: false # Show line numbers @@ -57,21 +56,10 @@ settings:
    `enabled`
    Enable or disable syntax highlighting (default: `true`)
    -
    `lexer`
    -
    - Specify the lexer to use for syntax highlighting: -
    -
    `yaml`
    -
    For YAML output
    -
    `json`
    -
    For JSON output
    -
    -
    -
    `formatter`
    Output formatter (default: `terminal`)
    -
    `style`
    +
    `theme`
    Color scheme for syntax highlighting. Available options include:
      @@ -118,31 +106,6 @@ atmos describe config | grep base_path ``` -## Default Settings - -If not specified in your `atmos.yaml`, Atmos uses these default settings: - -```yaml -settings: - terminal: - max_width: 120 - use_pager: false - timestamps: false - colors: true - unicode: true - syntax_highlighting: - enabled: true - lexer: yaml - formatter: terminal - style: dracula - use_pager: false - options: - line_numbers: false - wrap: false -``` - -You can override any of these settings in your [Atmos CLI configuration](/cli/configuration) file. - ## Supported Themes Atmos supports a wide range of themes for syntax highlighting. You can find the full list of supported themes [here](https://xyproto.github.io/splash/docs/). \ No newline at end of file From ccaa34528fea69255c7b8a846ab50f143147367d Mon Sep 17 00:00:00 2001 From: Cerebrovinny Date: Thu, 9 Jan 2025 08:33:05 +0000 Subject: [PATCH 08/11] added theme --- atmos.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/atmos.yaml b/atmos.yaml index d6a6dd788..172e9804e 100644 --- a/atmos.yaml +++ b/atmos.yaml @@ -329,7 +329,7 @@ settings: syntax_highlighting: enabled: true formatter: terminal # Output formatter (e.g., terminal, html) - style: dracula # Highlighting style + theme: dracula # Highlighting theme pager: true # Enable pager options: line_numbers: true # Display line numbers From f8627fae5eae593244a0ea0e4b807445445d7407 Mon Sep 17 00:00:00 2001 From: Cerebrovinny Date: Thu, 9 Jan 2025 11:41:14 +0000 Subject: [PATCH 09/11] refactor pager --- pkg/schema/schema.go | 18 +++++++--------- pkg/utils/highlight_utils.go | 23 +++++++++++---------- website/docs/cli/configuration/terminal.mdx | 20 +++++++----------- 3 files changed, 26 insertions(+), 35 deletions(-) diff --git a/pkg/schema/schema.go b/pkg/schema/schema.go index 3a2d61d0b..cb05d1635 100644 --- a/pkg/schema/schema.go +++ b/pkg/schema/schema.go @@ -47,17 +47,13 @@ type Terminal struct { } type SyntaxHighlighting struct { - Enabled bool `yaml:"enabled" json:"enabled" mapstructure:"enabled"` - Lexer string `yaml:"lexer" json:"lexer" mapstructure:"lexer"` - Formatter string `yaml:"formatter" json:"formatter" mapstructure:"formatter"` - Theme string `yaml:"theme" json:"theme" mapstructure:"theme"` - UsePager bool `yaml:"pager" json:"pager" mapstructure:"pager"` - Options HighlightOptions `yaml:"options" json:"options" mapstructure:"options"` -} - -type HighlightOptions struct { - LineNumbers bool `yaml:"line_numbers" json:"line_numbers" mapstructure:"line_numbers"` - Wrap bool `yaml:"wrap" json:"wrap" mapstructure:"wrap"` + Enabled bool `yaml:"enabled" json:"enabled" mapstructure:"enabled"` + Lexer string `yaml:"lexer" json:"lexer" mapstructure:"lexer"` + Formatter string `yaml:"formatter" json:"formatter" mapstructure:"formatter"` + Theme string `yaml:"theme" json:"theme" mapstructure:"theme"` + UsePager bool `yaml:"pager" json:"pager" mapstructure:"pager"` + LineNumbers bool `yaml:"line_numbers" json:"line_numbers" mapstructure:"line_numbers"` + Wrap bool `yaml:"wrap" json:"wrap" mapstructure:"wrap"` } type AtmosSettings struct { diff --git a/pkg/utils/highlight_utils.go b/pkg/utils/highlight_utils.go index 0ced05a2f..b09bc5b6e 100644 --- a/pkg/utils/highlight_utils.go +++ b/pkg/utils/highlight_utils.go @@ -21,14 +21,12 @@ import ( // DefaultHighlightSettings returns the default syntax highlighting settings func DefaultHighlightSettings() *schema.SyntaxHighlighting { return &schema.SyntaxHighlighting{ - Enabled: true, - Formatter: "terminal", - Theme: "dracula", - UsePager: true, - Options: schema.HighlightOptions{ - LineNumbers: true, - Wrap: false, - }, + Enabled: true, + Formatter: "terminal", + Theme: "dracula", + UsePager: true, + LineNumbers: true, + Wrap: false, } } @@ -49,8 +47,11 @@ func GetHighlightSettings(config schema.AtmosConfiguration) *schema.SyntaxHighli if settings.Theme == "" { settings.Theme = defaults.Theme } - if settings.Options == (schema.HighlightOptions{}) { - settings.Options = defaults.Options + if !settings.LineNumbers { + settings.LineNumbers = defaults.LineNumbers + } + if !settings.Wrap { + settings.Wrap = defaults.Wrap } return settings } @@ -121,7 +122,7 @@ func HighlightCodeWithConfig(code string, config schema.AtmosConfiguration, form } // Get formatter var formatter chroma.Formatter - if settings.Options.LineNumbers { + if settings.LineNumbers { formatter = formatters.TTY256 } else { formatter = formatters.Get(settings.Formatter) diff --git a/website/docs/cli/configuration/terminal.mdx b/website/docs/cli/configuration/terminal.mdx index fe56aae64..fca63f97d 100644 --- a/website/docs/cli/configuration/terminal.mdx +++ b/website/docs/cli/configuration/terminal.mdx @@ -45,9 +45,8 @@ settings: formatter: terminal # Output formatter theme: dracula # Color scheme to use use_pager: false # Whether to use a pager for highlighted output - options: - line_numbers: false # Show line numbers - wrap: false # Wrap long lines + line_numbers: false # Show line numbers + wrap: false # Wrap long lines ``` ### Configuration Options @@ -75,16 +74,11 @@ settings:
      `use_pager`
      Whether to use a pager specifically for syntax-highlighted output (default: `false`)
      -
      `options`
      -
      - Additional formatting options: -
      -
      `line_numbers`
      -
      Show line numbers in output (default: `false`)
      -
      `wrap`
      -
      Wrap long lines (default: `false`)
      -
      -
      +
      `line_numbers`
      +
      Show line numbers in output (default: `false`)
      + +
      `wrap`
      +
      Wrap long lines (default: `false`)
      ### Example Usage From c654292373ba465e84789816a6c4b1bfb6dc7363 Mon Sep 17 00:00:00 2001 From: Cerebrovinny Date: Thu, 9 Jan 2025 12:57:57 +0000 Subject: [PATCH 10/11] improvements refactoring pager --- atmos.yaml | 16 +++++++--------- cmd/docs.go | 8 ++++---- pkg/config/config.go | 16 +++++++--------- pkg/schema/schema.go | 16 ++++++++-------- pkg/utils/highlight_utils.go | 15 +++++++++------ website/docs/cli/configuration/terminal.mdx | 17 ++++++++--------- 6 files changed, 43 insertions(+), 45 deletions(-) diff --git a/atmos.yaml b/atmos.yaml index 172e9804e..734206ff0 100644 --- a/atmos.yaml +++ b/atmos.yaml @@ -320,20 +320,18 @@ settings: # Terminal settings for displaying content terminal: - max_width: 120 # Maximum width for terminal output - pager: true # Use pager for long output - timestamps: false # Show timestamps in logs - colors: true # Enable colored output - unicode: true # Use unicode characters + max_width: 120 # Maximum width for terminal output + pager: true # Pager setting for all terminal output + timestamps: false # Show timestamps in logs + colors: true # Enable colored output + unicode: true # Use unicode characters syntax_highlighting: enabled: true formatter: terminal # Output formatter (e.g., terminal, html) theme: dracula # Highlighting theme - pager: true # Enable pager - options: - line_numbers: true # Display line numbers - wrap: false # Wrap long lines + line_numbers: true # Display line numbers + wrap: false # Wrap long lines # Markdown element styling markdown: diff --git a/cmd/docs.go b/cmd/docs.go index f9d3e4bc9..40a672b98 100644 --- a/cmd/docs.go +++ b/cmd/docs.go @@ -101,13 +101,13 @@ var docsCmd = &cobra.Command{ u.LogErrorAndExit(schema.AtmosConfiguration{}, err) } - usePager := atmosConfig.Settings.Terminal.UsePager - if !usePager && atmosConfig.Settings.Docs.Pagination { - usePager = atmosConfig.Settings.Docs.Pagination + pager := atmosConfig.Settings.Terminal.Pager + if !pager && atmosConfig.Settings.Docs.Pagination { + pager = atmosConfig.Settings.Docs.Pagination u.LogWarning(atmosConfig, "'settings.docs.pagination' is deprecated and will be removed in a future version. Please use 'settings.terminal.pager' instead") } - if err := u.DisplayDocs(componentDocs, usePager); err != nil { + if err := u.DisplayDocs(componentDocs, pager); err != nil { u.LogErrorAndExit(schema.AtmosConfiguration{}, fmt.Errorf("failed to display documentation: %w", err)) } diff --git a/pkg/config/config.go b/pkg/config/config.go index cfa87ea0d..a97b33628 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -58,18 +58,16 @@ var ( ListMergeStrategy: "replace", Terminal: schema.Terminal{ MaxWidth: templates.GetTerminalWidth(), - UsePager: true, + Pager: true, Colors: true, Unicode: true, SyntaxHighlighting: schema.SyntaxHighlighting{ - Enabled: true, - Formatter: "terminal", - Theme: "dracula", - UsePager: true, - Options: schema.HighlightOptions{ - LineNumbers: true, - Wrap: false, - }, + Enabled: true, + Formatter: "terminal", + Theme: "dracula", + HighlightedOutputPager: true, + LineNumbers: true, + Wrap: false, }, }, }, diff --git a/pkg/schema/schema.go b/pkg/schema/schema.go index cb05d1635..845f150dd 100644 --- a/pkg/schema/schema.go +++ b/pkg/schema/schema.go @@ -39,7 +39,7 @@ type AtmosConfiguration struct { type Terminal struct { MaxWidth int `yaml:"max_width" json:"max_width" mapstructure:"max_width"` - UsePager bool `yaml:"pager" json:"pager" mapstructure:"pager"` + Pager bool `yaml:"pager" json:"pager" mapstructure:"pager"` Timestamps bool `yaml:"timestamps" json:"timestamps" mapstructure:"timestamps"` Colors bool `yaml:"colors" json:"colors" mapstructure:"colors"` Unicode bool `yaml:"unicode" json:"unicode" mapstructure:"unicode"` @@ -47,13 +47,13 @@ type Terminal struct { } type SyntaxHighlighting struct { - Enabled bool `yaml:"enabled" json:"enabled" mapstructure:"enabled"` - Lexer string `yaml:"lexer" json:"lexer" mapstructure:"lexer"` - Formatter string `yaml:"formatter" json:"formatter" mapstructure:"formatter"` - Theme string `yaml:"theme" json:"theme" mapstructure:"theme"` - UsePager bool `yaml:"pager" json:"pager" mapstructure:"pager"` - LineNumbers bool `yaml:"line_numbers" json:"line_numbers" mapstructure:"line_numbers"` - Wrap bool `yaml:"wrap" json:"wrap" mapstructure:"wrap"` + Enabled bool `yaml:"enabled" json:"enabled" mapstructure:"enabled"` + Lexer string `yaml:"lexer" json:"lexer" mapstructure:"lexer"` + Formatter string `yaml:"formatter" json:"formatter" mapstructure:"formatter"` + Theme string `yaml:"theme" json:"theme" mapstructure:"theme"` + HighlightedOutputPager bool `yaml:"pager" json:"pager" mapstructure:"pager"` + LineNumbers bool `yaml:"line_numbers" json:"line_numbers" mapstructure:"line_numbers"` + Wrap bool `yaml:"wrap" json:"wrap" mapstructure:"wrap"` } type AtmosSettings struct { diff --git a/pkg/utils/highlight_utils.go b/pkg/utils/highlight_utils.go index b09bc5b6e..11bae1345 100644 --- a/pkg/utils/highlight_utils.go +++ b/pkg/utils/highlight_utils.go @@ -21,12 +21,12 @@ import ( // DefaultHighlightSettings returns the default syntax highlighting settings func DefaultHighlightSettings() *schema.SyntaxHighlighting { return &schema.SyntaxHighlighting{ - Enabled: true, - Formatter: "terminal", - Theme: "dracula", - UsePager: true, - LineNumbers: true, - Wrap: false, + Enabled: true, + Formatter: "terminal", + Theme: "dracula", + HighlightedOutputPager: true, + LineNumbers: true, + Wrap: false, } } @@ -47,6 +47,9 @@ func GetHighlightSettings(config schema.AtmosConfiguration) *schema.SyntaxHighli if settings.Theme == "" { settings.Theme = defaults.Theme } + if !settings.HighlightedOutputPager { + settings.HighlightedOutputPager = defaults.HighlightedOutputPager + } if !settings.LineNumbers { settings.LineNumbers = defaults.LineNumbers } diff --git a/website/docs/cli/configuration/terminal.mdx b/website/docs/cli/configuration/terminal.mdx index fca63f97d..b5e48be25 100644 --- a/website/docs/cli/configuration/terminal.mdx +++ b/website/docs/cli/configuration/terminal.mdx @@ -27,7 +27,7 @@ Configure general terminal behavior. These are also the default settings if not settings: terminal: max_width: 120 # Maximum width for terminal output - use_pager: false # Whether to use a pager (like 'less') for long output + pager: false # Pager setting for all terminal output timestamps: false # Show timestamps in output colors: true # Enable colored output unicode: true # Use Unicode characters in output @@ -41,12 +41,11 @@ You can customize the syntax highlighting behavior for terminal output using the settings: terminal: syntax_highlighting: - enabled: true # Enable/disable syntax highlighting - formatter: terminal # Output formatter - theme: dracula # Color scheme to use - use_pager: false # Whether to use a pager for highlighted output - line_numbers: false # Show line numbers - wrap: false # Wrap long lines + enabled: true # Enable/disable syntax highlighting + formatter: terminal # Output formatter + theme: dracula # Color scheme to use + line_numbers: false # Show line numbers + wrap: false # Wrap long lines ``` ### Configuration Options @@ -71,8 +70,8 @@ settings: You can find the full list of supported themes [here](https://xyproto.github.io/splash/docs/).
    -
    `use_pager`
    -
    Whether to use a pager specifically for syntax-highlighted output (default: `false`)
    +
    `pager`
    +
    Whether to use a pager specifically for syntax-highlighted output. This setting is independent of the pager setting (default: `false`)
    `line_numbers`
    Show line numbers in output (default: `false`)
    From 64c2ab1bfc64cd4deb19571743f5d8b8a8aec245 Mon Sep 17 00:00:00 2001 From: Cerebrovinny Date: Fri, 10 Jan 2025 20:59:58 +0000 Subject: [PATCH 11/11] remove timestamps --- atmos.yaml | 1 - pkg/schema/schema.go | 1 - website/docs/cli/configuration/markdown-styling.mdx | 1 - website/docs/cli/configuration/terminal.mdx | 3 +-- 4 files changed, 1 insertion(+), 5 deletions(-) diff --git a/atmos.yaml b/atmos.yaml index 734206ff0..c3e10fc53 100644 --- a/atmos.yaml +++ b/atmos.yaml @@ -322,7 +322,6 @@ settings: terminal: max_width: 120 # Maximum width for terminal output pager: true # Pager setting for all terminal output - timestamps: false # Show timestamps in logs colors: true # Enable colored output unicode: true # Use unicode characters diff --git a/pkg/schema/schema.go b/pkg/schema/schema.go index 845f150dd..152ef9f9c 100644 --- a/pkg/schema/schema.go +++ b/pkg/schema/schema.go @@ -40,7 +40,6 @@ type AtmosConfiguration struct { type Terminal struct { MaxWidth int `yaml:"max_width" json:"max_width" mapstructure:"max_width"` Pager bool `yaml:"pager" json:"pager" mapstructure:"pager"` - Timestamps bool `yaml:"timestamps" json:"timestamps" mapstructure:"timestamps"` 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"` diff --git a/website/docs/cli/configuration/markdown-styling.mdx b/website/docs/cli/configuration/markdown-styling.mdx index 5d5bd9746..dfc73b63a 100644 --- a/website/docs/cli/configuration/markdown-styling.mdx +++ b/website/docs/cli/configuration/markdown-styling.mdx @@ -25,7 +25,6 @@ settings: terminal: max_width: 120 # Maximum width for terminal output pager: true # Use pager for long output - timestamps: false colors: true unicode: true diff --git a/website/docs/cli/configuration/terminal.mdx b/website/docs/cli/configuration/terminal.mdx index b5e48be25..6844e1c20 100644 --- a/website/docs/cli/configuration/terminal.mdx +++ b/website/docs/cli/configuration/terminal.mdx @@ -27,8 +27,7 @@ Configure general terminal behavior. These are also the default settings if not settings: terminal: max_width: 120 # Maximum width for terminal output - pager: false # Pager setting for all terminal output - timestamps: false # Show timestamps in output + pager: true # Pager setting for all terminal output colors: true # Enable colored output unicode: true # Use Unicode characters in output ```