aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWill Eccles <[email protected]>2019-04-04 12:48:29 -0400
committerWill Eccles <[email protected]>2019-04-04 12:48:29 -0400
commite4b86316185f10a4dc9d3fce93a2e9229c08200c (patch)
tree5a2556185542735977f4d169001789a256d353dd
parentAdded support for kitty, both input and output (diff)
downloadschemer2-e4b86316185f10a4dc9d3fce93a2e9229c08200c.tar.xz
schemer2-e4b86316185f10a4dc9d3fce93a2e9229c08200c.zip
kitty input is now sorted
-rw-r--r--input.go10
1 files changed, 8 insertions, 2 deletions
diff --git a/input.go b/input.go
index a1d4073..11490af 100644
--- a/input.go
+++ b/input.go
@@ -8,6 +8,7 @@ import (
"regexp"
"strconv"
"strings"
+ "sort"
)
func readFile(filename string) (string, error) {
@@ -277,12 +278,17 @@ func inputKittyTerm(filename string) ([]color.Color, error) {
re := regexp.MustCompile("^color[0-9]*")
for _, l := range lines {
if len(re.FindAllString(l, 1)) != 0 {
- colorlines = append(colorlines, l)
+ 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
- // 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