diff options
| author | Will Eccles <[email protected]> | 2019-04-04 12:28:34 -0400 |
|---|---|---|
| committer | Will Eccles <[email protected]> | 2019-04-04 12:28:34 -0400 |
| commit | 87b1d2ba3bfa3e7b5478b360130c424fef52bfbf (patch) | |
| tree | f7309607538455ef8bab7ee9777faa3574448df2 /input.go | |
| parent | Removed abort on less than 16 colors generated (diff) | |
| download | schemer2-87b1d2ba3bfa3e7b5478b360130c424fef52bfbf.tar.xz schemer2-87b1d2ba3bfa3e7b5478b360130c424fef52bfbf.zip | |
Added support for kitty, both input and output
Diffstat (limited to 'input.go')
| -rw-r--r-- | input.go | 45 |
1 files changed, 45 insertions, 0 deletions
@@ -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' +} |