diff options
| author | Daniel Byron <[email protected]> | 2019-04-06 15:21:08 +1100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2019-04-06 15:21:08 +1100 |
| commit | 952e6132a527d346486d2febe6bdaa744f562498 (patch) | |
| tree | a297b5cc0b58f85212d376d46e3c72f5028c8e11 | |
| parent | Removed abort on less than 16 colors generated (diff) | |
| parent | strings.fieldsfunc -> strings.fields (diff) | |
| download | schemer2-952e6132a527d346486d2febe6bdaa744f562498.tar.xz schemer2-952e6132a527d346486d2febe6bdaa744f562498.zip | |
Merge pull request #7 from WillEccles/master
Kitty input/output
| -rw-r--r-- | format.go | 6 | ||||
| -rw-r--r-- | input.go | 47 | ||||
| -rw-r--r-- | output.go | 15 |
3 files changed, 68 insertions, 0 deletions
@@ -91,4 +91,10 @@ var formats = []Format{ flagName: "gnome-terminal", output: printGnomeDConf, }, + { + friendlyName: "Kitty Terminal", + flagName: "kitty", + output: printKittyTerm, + input: inputKittyTerm, + }, } @@ -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 +} @@ -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 +} |