summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-12-17 13:31:37 +0100
committerDimitri Sokolyuk <demon@dim13.org>2016-12-17 13:31:37 +0100
commit3faa0bfb54e4368223ac7f0a894112e6f9266fa2 (patch)
tree65f0277bec69a1d4043c0f56348c709636d09772
Initial import
-rw-r--r--main.go117
1 files changed, 117 insertions, 0 deletions
diff --git a/main.go b/main.go
new file mode 100644
index 0000000..b5b0174
--- /dev/null
+++ b/main.go
@@ -0,0 +1,117 @@
+package main
+
+import (
+ "flag"
+ "fmt"
+ "io/ioutil"
+ "log"
+ "math"
+ "os"
+ "path/filepath"
+ "strings"
+ "text/template"
+
+ plist "github.com/DHowett/go-plist"
+)
+
+type Color struct {
+ Alpha float64 `plist:"Alpha Component"`
+ Red float64 `plist:"Red Component"`
+ Green float64 `plist:"Green Component"`
+ Blue float64 `plist:"Blue Component"`
+ Space string `plist:"Color Space"`
+}
+
+func (c Color) String() string {
+ r := int(math.MaxUint8 * c.Red)
+ g := int(math.MaxUint8 * c.Green)
+ b := int(math.MaxUint8 * c.Blue)
+ return fmt.Sprintf("#%02x%02x%02x", r, g, b)
+}
+
+const t = `! Color scheme: {{.Name}}
+*VT100*foreground: {{.Foreground}}
+*VT100*background: {{.Background}}
+*VT100*cursorColor: {{.Cursor}}
+! Black
+*VT100*color0: {{.Ansi0}}
+*VT100*color8: {{.Ansi8}}
+! Red
+*VT100*color1: {{.Ansi1}}
+*VT100*color9: {{.Ansi9}}
+! Green
+*VT100*color2: {{.Ansi2}}
+*VT100*color10: {{.Ansi10}}
+! Yellow
+*VT100*color3: {{.Ansi3}}
+*VT100*color11: {{.Ansi11}}
+! Blue
+*VT100*color4: {{.Ansi4}}
+*VT100*color12: {{.Ansi12}}
+! Magenta
+*VT100*color5: {{.Ansi5}}
+*VT100*color13: {{.Ansi13}}
+! Cyan
+*VT100*color6: {{.Ansi6}}
+*VT100*color14: {{.Ansi14}}
+! White
+*VT100*color7: {{.Ansi7}}
+*VT100*color15: {{.Ansi15}}
+! Bold
+*VT100*colorBD: {{.Bold}}
+!*VT100*colorIT:
+!*VT100*colorUL:
+`
+
+type Scheme struct {
+ Name string
+ Ansi0 Color `plist:"Ansi 0 Color"`
+ Ansi1 Color `plist:"Ansi 1 Color"`
+ Ansi2 Color `plist:"Ansi 2 Color"`
+ Ansi3 Color `plist:"Ansi 3 Color"`
+ Ansi4 Color `plist:"Ansi 4 Color"`
+ Ansi5 Color `plist:"Ansi 5 Color"`
+ Ansi6 Color `plist:"Ansi 6 Color"`
+ Ansi7 Color `plist:"Ansi 7 Color"`
+ Ansi8 Color `plist:"Ansi 8 Color"`
+ Ansi9 Color `plist:"Ansi 9 Color"`
+ Ansi10 Color `plist:"Ansi 10 Color"`
+ Ansi11 Color `plist:"Ansi 11 Color"`
+ Ansi12 Color `plist:"Ansi 12 Color"`
+ Ansi13 Color `plist:"Ansi 13 Color"`
+ Ansi14 Color `plist:"Ansi 14 Color"`
+ Ansi15 Color `plist:"Ansi 15 Color"`
+ Background Color `plist:"Background Color"`
+ Badge Color `plist:"Badge Color"`
+ Bold Color `plist:"Bold Color"`
+ Cursor Color `plist:"Cursor Color"`
+ CursorGuide Color `plist:"Cursor Guide Color"`
+ CursorText Color `plist:"Cursor Text Color"`
+ Foreground Color `plist:"Foreground Color"`
+ Link Color `plist:"Link Color"`
+ SelectedText Color `plist:"Selected Text Color"`
+ Selection Color `plist:"Selection Color"`
+}
+
+func name(s string) string {
+ return strings.TrimSuffix(filepath.Base(s), filepath.Ext(s))
+}
+
+func main() {
+ file := flag.String("file", "", "Color scheme .itemcolors")
+ flag.Parse()
+ body, err := ioutil.ReadFile(*file)
+ if err != nil {
+ log.Fatal(err)
+ }
+ var s Scheme
+ if _, err := plist.Unmarshal(body, &s); err != nil {
+ log.Fatal(err)
+ }
+ tmpl, err := template.New("xrdb").Parse(t)
+ if err != nil {
+ log.Fatal(err)
+ }
+ s.Name = name(*file)
+ tmpl.Execute(os.Stdout, s)
+}