Dedup code.

This commit is contained in:
Sascha L. Teichmann
2016-04-23 21:09:23 +02:00
parent 0db9b519a6
commit 607b4de9ec
4 changed files with 14 additions and 21 deletions

View File

@ -8,6 +8,7 @@ import (
"bufio"
"fmt"
"image/color"
"log"
"os"
"sort"
"strconv"
@ -136,6 +137,15 @@ func ParseColor(col string) (color.RGBA, error) {
A: 0xff}, nil
}
func ParseColorDefault(col string, def color.RGBA) color.RGBA {
c, err := ParseColor(col)
if err != nil {
log.Printf("WARN: cannot parse color '%s': %s\n", col, err)
return def
}
return c
}
func ColorToHex(col color.RGBA) string {
return fmt.Sprintf("#%02x%02x%02x", col.R, col.G, col.B)
}