From f20505e1f495be734e70c60069ad577569b0de4e Mon Sep 17 00:00:00 2001 From: Nuno Cruces Date: Sun, 19 Jan 2020 04:28:06 +0000 Subject: [PATCH] Color dialog (macos). --- color_darwin.go | 28 ++++++++++++ go.mod | 2 + go.sum | 3 ++ internal/osa/{osa.go => generate.go} | 0 internal/osa/generated.go | 15 +++++++ internal/osa/{osa_darwin.go => run_darwin.go} | 4 ++ internal/osa/scripts/color.gots | 17 +++++++ internal/zen/color.go | 44 +++++++++++++++++++ internal/zen/{zen_unix.go => run_unix.go} | 0 9 files changed, 113 insertions(+) create mode 100644 color_darwin.go rename internal/osa/{osa.go => generate.go} (100%) rename internal/osa/{osa_darwin.go => run_darwin.go} (96%) create mode 100644 internal/osa/scripts/color.gots create mode 100644 internal/zen/color.go rename internal/zen/{zen_unix.go => run_unix.go} (100%) diff --git a/color_darwin.go b/color_darwin.go new file mode 100644 index 0000000..686ee09 --- /dev/null +++ b/color_darwin.go @@ -0,0 +1,28 @@ +package zenity + +import ( + "image/color" + "os/exec" + + "github.com/ncruces/zenity/internal/osa" + "github.com/ncruces/zenity/internal/zen" +) + +func SelectColor(options ...Option) (color.Color, error) { + opts := optsParse(options) + + var data osa.Color + if opts.color != nil { + r, g, b, _ := opts.color.RGBA() + data.Color = []float32{float32(r) / 0xffff, float32(g) / 0xffff, float32(b) / 0xffff} + } + + out, err := osa.Run("color", data) + if err, ok := err.(*exec.ExitError); ok && err.ExitCode() == 1 { + return nil, nil + } + if err != nil { + return nil, err + } + return zen.ParseColor(string(out)), nil +} diff --git a/go.mod b/go.mod index b62b7b6..0d81813 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,5 @@ module github.com/ncruces/zenity go 1.13 + +require golang.org/x/image v0.0.0-20191214001246-9130b4cfad52 diff --git a/go.sum b/go.sum index e69de29..9760eff 100644 --- a/go.sum +++ b/go.sum @@ -0,0 +1,3 @@ +golang.org/x/image v0.0.0-20191214001246-9130b4cfad52 h1:2fktqPPvDiVEEVT/vSTeoUPXfmRxRaGy6GU8jypvEn0= +golang.org/x/image v0.0.0-20191214001246-9130b4cfad52/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/internal/osa/osa.go b/internal/osa/generate.go similarity index 100% rename from internal/osa/osa.go rename to internal/osa/generate.go diff --git a/internal/osa/generated.go b/internal/osa/generated.go index a855546..ab02535 100644 --- a/internal/osa/generated.go +++ b/internal/osa/generated.go @@ -6,6 +6,21 @@ package osa import "html/template" var scripts = template.Must(template.New("").Parse(` +{{define "color"}}{{end}} {{define "file"}}