| 1 |
// Package main is a simple command line tool for rendering the CharmTone color |
| 2 |
// palette. |
| 3 |
package main |
| 4 |
|
| 5 |
import ( |
| 6 |
"context" |
| 7 |
"fmt" |
| 8 |
"os" |
| 9 |
"strings" |
| 10 |
|
| 11 |
"github.com/charmbracelet/fang" |
| 12 |
"github.com/charmbracelet/x/exp/charmtone" |
| 13 |
"github.com/spf13/cobra" |
| 14 |
) |
| 15 |
|
| 16 |
const ( |
| 17 |
blackCircle = "●" |
| 18 |
whiteCircle = "○" |
| 19 |
rightArrow = "→" |
| 20 |
) |
| 21 |
|
| 22 |
func main() { |
| 23 |
rootCmd := &cobra.Command{ |
| 24 |
Use: "charmtone", |
| 25 |
Short: "CharmTone color palette tool", |
| 26 |
Long: "A command line tool for rendering the CharmTone color palette in various formats", |
| 27 |
Run: func(_ *cobra.Command, _ []string) { |
| 28 |
renderGuide() |
| 29 |
}, |
| 30 |
} |
| 31 |
|
| 32 |
cssCmd := &cobra.Command{ |
| 33 |
Use: "css", |
| 34 |
Short: "Generate CSS variables", |
| 35 |
Long: "Generate CSS custom properties (variables) for the CharmTone color palette", |
| 36 |
Run: func(_ *cobra.Command, _ []string) { |
| 37 |
renderCSS() |
| 38 |
}, |
| 39 |
} |
| 40 |
|
| 41 |
scssCmd := &cobra.Command{ |
| 42 |
Use: "scss", |
| 43 |
Short: "Print as SCSS variables", |
| 44 |
Long: "Print SCSS variables for the CharmTone color palette", |
| 45 |
Run: func(_ *cobra.Command, _ []string) { |
| 46 |
renderSCSS() |
| 47 |
}, |
| 48 |
} |
| 49 |
|
| 50 |
vimCmd := &cobra.Command{ |
| 51 |
Use: "vim", |
| 52 |
Short: "Generate Vim colorscheme", |
| 53 |
Long: "Generate Vim colorscheme using the CharmTone color palette", |
| 54 |
Run: func(_ *cobra.Command, _ []string) { |
| 55 |
renderVim() |
| 56 |
}, |
| 57 |
} |
| 58 |
|
| 59 |
rootCmd.AddCommand(cssCmd, scssCmd, vimCmd) |
| 60 |
|
| 61 |
// Use Fang to execute the command with enhanced styling and features |
| 62 |
if err := fang.Execute(context.Background(), rootCmd); err != nil { |
| 63 |
os.Exit(1) |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
func renderSCSS() { |
| 68 |
for _, k := range charmtone.Keys() { |
| 69 |
name := strings.ToLower(strings.ReplaceAll(k.String(), " ", "-")) |
| 70 |
fmt.Printf("$%s: %s;\n", name, k.Hex()) |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
func renderVim() { |
| 75 |
for _, k := range charmtone.Keys() { |
| 76 |
name := strings.ToLower(strings.ReplaceAll(k.String(), " ", "-")) |
| 77 |
fmt.Printf("let %s = '%s'\n", name, k.Hex()) |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
func renderCSS() { |
| 82 |
for _, k := range charmtone.Keys() { |
| 83 |
name := strings.ToLower(strings.ReplaceAll(k.String(), " ", "-")) |
| 84 |
fmt.Printf("--charmtone-%s: %s;\n", name, k.Hex()) |
| 85 |
} |
| 86 |
} |