zenity/color_darwin.go
2021-02-19 02:40:46 +00:00

33 lines
615 B
Go

package zenity
import (
"image/color"
"os/exec"
"github.com/ncruces/zenity/internal/zenutil"
)
func selectColor(options []Option) (color.Color, error) {
opts := applyOptions(options)
var col color.Color
if opts.color != nil {
col = opts.color
} else {
col = color.White
}
r, g, b, _ := col.RGBA()
out, err := zenutil.Run(opts.ctx, "color", []float32{
float32(r) / 0xffff,
float32(g) / 0xffff,
float32(b) / 0xffff,
})
if err, ok := err.(*exec.ExitError); ok && err.ExitCode() == 1 {
return nil, nil
}
if err != nil {
return nil, err
}
return zenutil.ParseColor(string(out)), nil
}