Skip to content

Add predefined color themes #30

@sgaunet

Description

@sgaunet

Feature Request

Add predefined color themes for convenience instead of requiring manual color configuration.

Current Behavior

Users must configure each color individually:

colors:
  enabled: true
  error: "\x1b[31m"    # Red
  warn: "\x1b[33m"     # Yellow
  info: "\x1b[32m"     # Green
  debug: "\x1b[34m"    # Blue
  reset: "\x1b[0m"

Proposed Feature

Add theme system with common presets:

colors:
  enabled: true
  theme: "solarized-dark"  # Use predefined theme

Proposed Themes

1. Default (current)

  • ERROR: Red
  • WARN: Yellow
  • INFO: Green
  • DEBUG: Blue

2. Solarized Dark

  • ERROR: Red (#dc322f)
  • WARN: Orange (#cb4b16)
  • INFO: Cyan (#2aa198)
  • DEBUG: Blue (#268bd2)

3. Solarized Light

  • ERROR: Red (#dc322f)
  • WARN: Orange (#cb4b16)
  • INFO: Blue (#268bd2)
  • DEBUG: Violet (#6c71c4)

4. Monokai

  • ERROR: Red (#f92672)
  • WARN: Orange (#fd971f)
  • INFO: Green (#a6e22e)
  • DEBUG: Purple (#ae81ff)

5. Nord

  • ERROR: Red (#bf616a)
  • WARN: Orange (#d08770)
  • INFO: Green (#a3be8c)
  • DEBUG: Blue (#81a1c1)

6. Dracula

  • ERROR: Red (#ff5555)
  • WARN: Orange (#ffb86c)
  • INFO: Green (#50fa7b)
  • DEBUG: Purple (#bd93f9)

7. Monochrome

  • ERROR: Bold white
  • WARN: White
  • INFO: Gray
  • DEBUG: Dark gray

Implementation

// pkg/config/themes.go

type ColorTheme struct {
    Error string
    Warn  string
    Info  string
    Debug string
    Reset string
}

var themes = map[string]ColorTheme{
    "default": {
        Error: "\x1b[31m",
        Warn:  "\x1b[33m",
        Info:  "\x1b[32m",
        Debug: "\x1b[34m",
        Reset: "\x1b[0m",
    },
    "solarized-dark": {
        Error: "\x1b[38;5;160m",  // Red
        Warn:  "\x1b[38;5;166m",  // Orange
        Info:  "\x1b[38;5;37m",   // Cyan
        Debug: "\x1b[38;5;33m",   // Blue
        Reset: "\x1b[0m",
    },
    "monokai": {
        Error: "\x1b[38;5;197m",  // Magenta
        Warn:  "\x1b[38;5;208m",  // Orange
        Info:  "\x1b[38;5;148m",  // Green
        Debug: "\x1b[38;5;141m",  // Purple
        Reset: "\x1b[0m",
    },
    "monochrome": {
        Error: "\x1b[1;37m",  // Bold white
        Warn:  "\x1b[37m",    // White
        Info:  "\x1b[90m",    // Gray
        Debug: "\x1b[2;37m",  // Dim white
        Reset: "\x1b[0m",
    },
}

func ApplyTheme(cfg *Config, themeName string) error {
    theme, exists := themes[themeName]
    if !exists {
        return fmt.Errorf("unknown theme: %s (available: %s)", 
            themeName, strings.Join(listThemes(), ", "))
    }
    
    cfg.Colors.Error = theme.Error
    cfg.Colors.Warn = theme.Warn
    cfg.Colors.Info = theme.Info
    cfg.Colors.Debug = theme.Debug
    cfg.Colors.Reset = theme.Reset
    
    return nil
}

Configuration

colors:
  enabled: true
  theme: "solarized-dark"
  
  # OR custom colors (overrides theme)
  error: "\x1b[31m"
  warn: "\x1b[33m"

Priority: Theme is applied first, then custom colors override.

CLI Usage

# Use theme
logwrap --theme solarized-dark -- myapp

# List themes
logwrap --list-themes
Available themes:
  - default
  - solarized-dark
  - solarized-light
  - monokai
  - nord
  - dracula
  - monochrome

# Preview theme
logwrap --preview-theme solarized-dark
ERROR: Example error message
WARN:  Example warning message
INFO:  Example info message
DEBUG: Example debug message

Benefits

User Experience:

  • ✅ Quick setup (one line instead of 5)
  • ✅ Professionally designed color schemes
  • ✅ Consistent color palettes
  • ✅ Easy to switch themes

Accessibility:

  • Different themes work better on different terminals
  • Light vs dark background support
  • Colorblind-friendly options

Implementation Checklist

  • Create themes.go with predefined themes
  • Add theme support to config parsing
  • Add CLI flag --theme
  • Add --list-themes flag
  • Add --preview-theme flag
  • Allow custom colors to override theme
  • Document themes in README
  • Add theme screenshots to docs/

Advanced Features (Future)

Custom theme files:

# ~/.config/logwrap/themes/mytheme.yaml
name: "My Custom Theme"
colors:
  error: "\x1b[31m"
  warn: "\x1b[33m"
  info: "\x1b[32m"
  debug: "\x1b[34m"
logwrap --theme ~/.config/logwrap/themes/mytheme.yaml -- myapp

Testing

Add theme tests:

func TestThemes(t *testing.T) {
    for name := range themes {
        t.Run(name, func(t *testing.T) {
            cfg := &Config{}
            err := ApplyTheme(cfg, name)
            assert.NoError(t, err)
            assert.NotEmpty(t, cfg.Colors.Error)
        })
    }
}

Documentation

Add theme gallery to README:

## Color Themes

LogWrap includes several built-in color themes:

### Default
![Default theme](docs/themes/default.png)

### Solarized Dark
![Solarized dark theme](docs/themes/solarized-dark.png)

### Usage
```bash
logwrap --theme solarized-dark -- myapp

### Related Issues

- #14 - Package documentation (document theme system)
- #24 - Examples (add theme examples)

### References

- Solarized: https://ethanschoonover.com/solarized/
- Nord: https://www.nordtheme.com/
- Dracula: https://draculatheme.com/

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions