-
Notifications
You must be signed in to change notification settings - Fork 2
Configuration
Warning
This whole file is a TODO and most things do not work yet.
This guide covers all configuration options available in Goshot, from basic settings to advanced customization.
Goshot respects the following environment variables:
# Font paths
GOSHOT_FONT_PATH # Additional directories to search for fonts
GOSHOT_FALLBACK_FONT # Path to a custom fallback font file
# Cache settings
GOSHOT_CACHE_DIR # Directory for caching fonts and other assets
GOSHOT_DISABLE_CACHE # Set to "1" to disable caching
The canvas is the main rendering surface and can be configured through the CodeStyle
struct:
style := &render.CodeStyle{
// Syntax highlighting options
Theme: "dracula", // Syntax highlighting theme
Language: "go", // Programming language
TabWidth: 4, // Number of spaces per tab
ShowLineNumbers: true, // Show line numbers
// Line number configuration
LineNumberRange: render.LineRange{
Start: 1, // First line number
End: 100, // Last line number
},
// Line highlighting
LineHighlightRanges: []render.LineRange{
{Start: 5, End: 8}, // Highlight lines 5-8
{Start: 12, End: 12}, // Highlight line 12
},
}
Each window chrome style can be configured using themes and options:
// Theme configuration
theme := chrome.Theme{
// Title bar appearance
TitleFont: "SF Pro",
TitleBackground: color.RGBA{R: 40, G: 40, B: 40, A: 255},
TitleText: color.RGBA{R: 200, G: 200, B: 200, A: 255},
ControlsColor: color.RGBA{R: 255, G: 255, B: 255, A: 255},
// Content area appearance
ContentBackground: color.RGBA{R: 30, G: 30, B: 30, A: 255},
TextColor: color.RGBA{R: 200, G: 200, B: 200, A: 255},
DarkTextColor: color.RGBA{R: 50, G: 50, B: 50, A: 255},
}
// Chrome options
chromeOpts := []chrome.ChromeOption{
chrome.WithTitle("main.go"),
chrome.WithDarkMode(true),
chrome.WithTitleBar(true),
chrome.WithCornerRadius(6),
}
// Apply configuration
windowChrome := chrome.NewMacChrome(chromeOpts...).
SetTheme(theme)
Different background types have their own configuration options:
// Solid color background
solidBg := background.NewColorBackground().
SetColor(color.RGBA{R: 30, G: 30, B: 30, A: 255}).
SetPadding(40).
SetCornerRadius(10)
// Gradient background
gradientBg := background.NewGradientBackground(
background.LinearGradient,
background.GradientStop{Color: color.RGBA{R: 30, G: 30, B: 30, A: 255}, Position: 0},
background.GradientStop{Color: color.RGBA{R: 60, G: 60, B: 60, A: 255}, Position: 1},
).SetAngle(45).
SetPadding(40).
SetCornerRadius(10)
// Image background
imageBg := background.NewImageBackground(img).
SetScaleMode(background.ImageScaleFill).
SetBlurRadius(3.0).
SetOpacity(0.9).
SetPadding(40).
SetCornerRadius(10)
Font management can be configured through styles and options:
// Font style configuration
style := &fonts.FontStyle{
Weight: fonts.WeightBold,
Italic: true,
Condensed: false,
Mono: false,
}
// Font face configuration
face, err := font.GetFontFace(14.0) // 14pt size
Here are some example configuration profiles for common use cases:
func DarkModeConfig() (*render.Canvas, error) {
// Chrome configuration
chromeTheme := chrome.Theme{
TitleBackground: color.RGBA{R: 40, G: 40, B: 40, A: 255},
TitleText: color.RGBA{R: 200, G: 200, B: 200, A: 255},
ContentBackground: color.RGBA{R: 30, G: 30, B: 30, A: 255},
}
windowChrome := chrome.NewMacChrome(
chrome.WithDarkMode(true),
chrome.WithCornerRadius(6),
).SetTheme(chromeTheme)
// Background configuration
bg := background.NewGradientBackground(
background.LinearGradient,
background.GradientStop{Color: color.RGBA{R: 30, G: 30, B: 30, A: 255}, Position: 0},
background.GradientStop{Color: color.RGBA{R: 50, G: 50, B: 50, A: 255}, Position: 1},
).SetPadding(40)
// Create and configure canvas
return render.NewCanvas().
SetChrome(windowChrome).
SetBackground(bg).
SetCodeStyle(&render.CodeStyle{
Theme: "dracula",
ShowLineNumbers: true,
TabWidth: 4,
}), nil
}
func LightModeConfig() (*render.Canvas, error) {
// Chrome configuration
chromeTheme := chrome.Theme{
TitleBackground: color.RGBA{R: 240, G: 240, B: 240, A: 255},
TitleText: color.RGBA{R: 50, G: 50, B: 50, A: 255},
ContentBackground: color.RGBA{R: 255, G: 255, B: 255, A: 255},
}
windowChrome := chrome.NewMacChrome(
chrome.WithDarkMode(false),
chrome.WithCornerRadius(6),
).SetTheme(chromeTheme)
// Background configuration
bg := background.NewColorBackground().
SetColor(color.RGBA{R: 255, G: 255, B: 255, A: 255}).
SetPadding(40)
// Create and configure canvas
return render.NewCanvas().
SetChrome(windowChrome).
SetBackground(bg).
SetCodeStyle(&render.CodeStyle{
Theme: "github",
ShowLineNumbers: true,
TabWidth: 4,
}), nil
}
-
Configuration Organization
- Keep related configuration options together
- Use configuration profiles for common scenarios
- Consider environment-specific configurations
-
Theme Consistency
- Maintain consistent colors across components
- Match background and chrome styles
- Consider accessibility in color choices
-
Performance
- Cache configuration profiles when possible
- Reuse theme and style objects
- Consider memory usage with complex configurations
-
Error Handling
func loadConfig() (*render.Canvas, error) { canvas := render.NewCanvas() // Load and validate each component if err := configureChrome(canvas); err != nil { return nil, fmt.Errorf("chrome config: %v", err) } if err := configureBackground(canvas); err != nil { return nil, fmt.Errorf("background config: %v", err) } if err := configureSyntax(canvas); err != nil { return nil, fmt.Errorf("syntax config: %v", err) } return canvas, nil }
While Goshot doesn't require a configuration file, you might want to create one for your application. Here's an example structure:
# goshot.yaml
chrome:
style: macos
dark_mode: true
corner_radius: 6
title: "Code Example"
theme:
title_font: "SF Pro"
title_background: "#282828"
title_text: "#C8C8C8"
background:
type: gradient
gradient:
style: linear
angle: 45
stops:
- color: "#1E1E1E"
position: 0
- color: "#323232"
position: 1
padding: 40
corner_radius: 10
code:
theme: dracula
tab_width: 4
show_line_numbers: true
highlight_lines: [5, 6, 7]
line_number_start: 1
fonts:
title: "SF Pro"
code: "JetBrains Mono"
fallback: "Liberation Sans"
You can then load this configuration in your application:
type Config struct {
Chrome ChromeConfig `yaml:"chrome"`
Background BackgroundConfig `yaml:"background"`
Code CodeConfig `yaml:"code"`
Fonts FontConfig `yaml:"fonts"`
}
func LoadConfig(path string) (*Config, error) {
data, err := os.ReadFile(path)
if err != nil {
return nil, err
}
var config Config
if err := yaml.Unmarshal(data, &config); err != nil {
return nil, err
}
return &config, nil
}
- 📥 Installation
- 🚀 CLI Usage (coming soon)
-
🤝 Contributing
- Code of Conduct
- Development Workflow
- Project Structure
- Guidelines
- Testing
- Documentation