zenity/color_darwin.go

30 lines
550 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
)
2020-01-26 11:04:49 -05:00
func selectColor(options []Option) (color.Color, error) {
2020-01-24 07:52:45 -05:00
opts := applyOptions(options)
2020-01-18 23:28:06 -05:00
2020-12-11 13:28:16 -05:00
var col color.Color
2020-01-18 23:28:06 -05:00
if opts.color != nil {
2020-12-11 13:28:16 -05:00
col = opts.color
} else {
col = color.White
2020-01-18 23:28:06 -05:00
}
2020-12-11 13:28:16 -05:00
r, g, b, _ := col.RGBA()
2020-01-18 23:28:06 -05:00
2020-12-11 13:28:16 -05:00
out, err := zenutil.Run(opts.ctx, "color", []uint32{r, g, b})
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
}