aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Byron <[email protected]>2019-04-06 15:21:08 +1100
committerGitHub <[email protected]>2019-04-06 15:21:08 +1100
commit952e6132a527d346486d2febe6bdaa744f562498 (patch)
treea297b5cc0b58f85212d376d46e3c72f5028c8e11
parentRemoved abort on less than 16 colors generated (diff)
parentstrings.fieldsfunc -> strings.fields (diff)
downloadschemer2-952e6132a527d346486d2febe6bdaa744f562498.tar.xz
schemer2-952e6132a527d346486d2febe6bdaa744f562498.zip
Merge pull request #7 from WillEccles/master
Kitty input/output
-rw-r--r--format.go6
-rw-r--r--input.go47
-rw-r--r--output.go15
3 files changed, 68 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..2cc9466 100644
--- a/input.go
+++ b/input.go
@@ -8,6 +8,7 @@ import (
"regexp"
"strconv"
"strings"
+ "sort"
)
func readFile(filename string) (string, error) {
@@ -256,3 +257,49 @@ 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, strings.Replace(l, "color", "", 1))
+ }
+ }
+
+ sort.Slice(colorlines, func(i, j int) bool {
+ numA, _ := strconv.Atoi(strings.TrimSpace(colorlines[i][:2]))
+ numB, _ := strconv.Atoi(strings.TrimSpace(colorlines[j][:2]))
+ return numA < numB
+ })
+
+ // Extract and parse colors
+ 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.Fields(l)
+ colorstring := splits[len(splits)-1]
+ col, err := parseColor(colorstring)
+ if err != nil {
+ return nil, err
+ }
+ colors = append(colors, col)
+ }
+
+ return colors, nil
+}
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
+}