zenity/color_unix.go

36 lines
706 B
Go
Raw Normal View History

2020-01-21 11:13:45 -05:00
// +build !windows,!darwin
package zenity
import (
"image/color"
"os/exec"
"github.com/ncruces/zenity/internal/zenutil"
)
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-21 11:13:45 -05:00
args := []string{"--color-selection"}
if opts.title != "" {
args = append(args, "--title", opts.title)
}
if opts.color != nil {
args = append(args, "--color", zenutil.UnparseColor(opts.color))
}
2020-01-24 07:52:45 -05:00
if opts.showPalette {
2020-01-21 11:13:45 -05:00
args = append(args, "--show-palette")
}
2020-01-28 07:46:43 -05:00
out, err := zenutil.Run(opts.ctx, args)
2020-01-21 11:13:45 -05:00
if err, ok := err.(*exec.ExitError); ok && err.ExitCode() != 255 {
return nil, nil
}
if err != nil {
return nil, err
}
return zenutil.ParseColor(string(out)), nil
}