Default color on macOS.

This commit is contained in:
Nuno Cruces 2020-12-11 18:28:16 +00:00
parent 91e2501ef6
commit 7cd382c0e9
5 changed files with 8 additions and 22 deletions

View File

@ -10,13 +10,15 @@ import (
func selectColor(options []Option) (color.Color, error) { func selectColor(options []Option) (color.Color, error) {
opts := applyOptions(options) opts := applyOptions(options)
var data zenutil.Color var col color.Color
if opts.color != nil { if opts.color != nil {
n := color.NRGBA64Model.Convert(opts.color).(color.NRGBA64) col = opts.color
data.Color = []uint16{n.R, n.G, n.B} } else {
col = color.White
} }
r, g, b, _ := col.RGBA()
out, err := zenutil.Run(opts.ctx, "color", data) out, err := zenutil.Run(opts.ctx, "color", []uint32{r, g, b})
if err, ok := err.(*exec.ExitError); ok && err.ExitCode() == 1 { if err, ok := err.(*exec.ExitError); ok && err.ExitCode() == 1 {
return nil, nil return nil, nil
} }

4
go.sum
View File

@ -1,9 +1,5 @@
github.com/akavel/rsrc v0.8.0 h1:zjWn7ukO9Kc5Q62DOJCcxGpXC18RawVtYAGdz2aLlfw=
github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/josephspurrier/goversioninfo v1.2.0 h1:tpLHXAxLHKHg/dCU2AAYx08A4m+v9/CWg6+WUvTF4uQ=
github.com/josephspurrier/goversioninfo v1.2.0/go.mod h1:AGP2a+Y/OVJZ+s6XM4IwFUpkETwvn0orYurY8qpw1+0=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=

View File

@ -13,11 +13,7 @@ var scripts = template.Must(template.New("").Funcs(template.FuncMap{"json": func
{{define "color" -}} {{define "color" -}}
tell application (path to frontmost application as text) tell application (path to frontmost application as text)
activate activate
{{if .Color -}} set c to choose color default color { {{index . 0}},{{index . 1}},{{index . 2}} }
set c to choose color default color { {{index .Color 0}},{{index .Color 1}},{{index .Color 2}} }
{{else -}}
set c to choose color
{{end}}
"rgb(" & (item 1 of c) div 256 & "," & (item 2 of c) div 256 & "," & (item 3 of c) div 256 & ")" "rgb(" & (item 1 of c) div 256 & "," & (item 2 of c) div 256 & "," & (item 3 of c) div 256 & ")"
end tell end tell
{{- end}} {{- end}}

View File

@ -1,9 +1,5 @@
tell application (path to frontmost application as text) tell application (path to frontmost application as text)
activate activate
{{if .Color -}} set c to choose color default color { {{index . 0}},{{index . 1}},{{index . 2}} }
set c to choose color default color { {{index .Color 0}},{{index .Color 1}},{{index .Color 2}} }
{{else -}}
set c to choose color
{{end}}
"rgb(" & (item 1 of c) div 256 & "," & (item 2 of c) div 256 & "," & (item 3 of c) div 256 & ")" "rgb(" & (item 1 of c) div 256 & "," & (item 2 of c) div 256 & "," & (item 3 of c) div 256 & ")"
end tell end tell

View File

@ -56,10 +56,6 @@ type File struct {
Multiple bool Multiple bool
} }
type Color struct {
Color []uint16
}
type Msg struct { type Msg struct {
Operation string Operation string
Text string Text string