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