zenity/color_darwin.go

28 lines
575 B
Go
Raw Normal View History

2020-01-18 23:28:06 -05:00
package zenity
import (
"image/color"
"os/exec"
2020-01-19 06:57:05 -05:00
"github.com/ncruces/zenity/internal/zenutil"
2020-01-18 23:28:06 -05:00
)
func SelectColor(options ...Option) (color.Color, error) {
opts := optsParse(options)
2020-01-19 06:57:05 -05:00
var data zenutil.Color
2020-01-18 23:28:06 -05:00
if opts.color != nil {
r, g, b, _ := opts.color.RGBA()
data.Color = []float32{float32(r) / 0xffff, float32(g) / 0xffff, float32(b) / 0xffff}
}
2020-01-19 06:57:05 -05:00
out, err := zenutil.Run("color", data)
2020-01-18 23:28:06 -05:00
if err, ok := err.(*exec.ExitError); ok && err.ExitCode() == 1 {
return nil, nil
}
if err != nil {
return nil, err
}
2020-01-19 06:57:05 -05:00
return zenutil.ParseColor(string(out)), nil
2020-01-18 23:28:06 -05:00
}