aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWill Eccles <[email protected]>2019-04-04 12:28:34 -0400
committerWill Eccles <[email protected]>2019-04-04 12:28:34 -0400
commit87b1d2ba3bfa3e7b5478b360130c424fef52bfbf (patch)
treef7309607538455ef8bab7ee9777faa3574448df2
parentRemoved abort on less than 16 colors generated (diff)
downloadschemer2-87b1d2ba3bfa3e7b5478b360130c424fef52bfbf.tar.xz
schemer2-87b1d2ba3bfa3e7b5478b360130c424fef52bfbf.zip
Added support for kitty, both input and output
-rw-r--r--format.go6
-rw-r--r--input.go45
-rw-r--r--output.go15
3 files changed, 66 insertions, 0 deletions
diff --git a/format.go b/format.go
index fda8bd1..ee2809f 100644
--- a/format.go
+++ b/format.go
@@ -91,4 +91,10 @@ var formats = []Format{
flagName: "gnome-terminal",
output: printGnomeDConf,
},
+ {
+ friendlyName: "Kitty Terminal",
+ flagName: "kitty",
+ output: printKittyTerm,
+ input: inputKittyTerm,
+ },
}
diff --git a/input.go b/input.go
index 37aeb75..a1d4073 100644
--- a/input.go
+++ b/input.go
@@ -256,3 +256,48 @@ func inputXterm(filename string) ([]color.Color, error) {
return colors, nil
}
+
+func inputKittyTerm(filename string) ([]color.Color, error) {
+ // Read in file
+ config, err := readFile(filename)
+ if err != nil {
+ return nil, err
+ }
+
+ // Split into lines
+ lines := strings.Split(config, "\n")
+
+ // Remove all spaces
+ //for i, l := range lines {
+ // lines[i] = strings.Replace(l, " ", "", -1)
+ //}
+
+ colorlines := make([]string, 0)
+ // Search for lines containing color information
+ re := regexp.MustCompile("^color[0-9]*")
+ for _, l := range lines {
+ if len(re.FindAllString(l, 1)) != 0 {
+ colorlines = append(colorlines, l)
+ }
+ }
+
+ // Extract and parse colors
+ // TODO: Sort by number first?
+ colors := make([]color.Color, 0)
+ for _, l := range colorlines {
+ // Assuming the color to be the rightmost half of the last instance of space/tab
+ splits := strings.FieldsFunc(l, KittySplit)
+ colorstring := splits[len(splits)-1]
+ col, err := parseColor(colorstring)
+ if err != nil {
+ return nil, err
+ }
+ colors = append(colors, col)
+ }
+
+ return colors, nil
+}
+
+func KittySplit(r rune) bool {
+ return r == ' ' || r == '\t'
+}
diff --git a/output.go b/output.go
index 9441c33..3fbfce5 100644
--- a/output.go
+++ b/output.go
@@ -268,3 +268,18 @@ func printGnomeDConf(colors []color.Color) string {
output += "\n"
return output
}
+
+func printKittyTerm(colors []color.Color) string {
+ output := ""
+ for i, c := range colors {
+ cc := c.(color.NRGBA)
+ bytes := []byte{byte(cc.R), byte(cc.G), byte(cc.B)}
+ output += "color"
+ output += strconv.Itoa(i)
+ output += "\t#"
+ output += hex.EncodeToString(bytes)
+ output += "\n"
+ }
+
+ return output
+}