WIP: zenity command (macos).

This commit is contained in:
Nuno Cruces 2020-01-07 00:57:00 +00:00
parent 7fe6837b4f
commit ec8eb571eb
9 changed files with 47 additions and 4 deletions

2
.gitignore vendored
View file

@ -13,5 +13,3 @@
# Dependency directories (remove the comment below to include it) # Dependency directories (remove the comment below to include it)
# vendor/ # vendor/
osa_gen_darwin.go

View file

@ -1 +1 @@
# Zenity for Golang # Zenity dialogs for Golang, Windows and macOS

1
cmd/zenity/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
zenity

24
cmd/zenity/main.go Normal file
View file

@ -0,0 +1,24 @@
package main
import (
"os"
"github.com/ncruces/zenity"
"github.com/ncruces/zenity/internal/cmd"
)
func main() {
cmd.Command = true
file, err := zenity.SelectFile()
if err != nil {
os.Stderr.WriteString(err.Error())
os.Stderr.WriteString("\n")
os.Exit(255)
}
if file == "" {
os.Exit(1)
}
os.Stdout.WriteString(file)
os.Stdout.WriteString("\n")
}

3
internal/cmd/cmd.go Normal file
View file

@ -0,0 +1,3 @@
package cmd
var Command bool

1
internal/osa/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
osa_gen_darwin.go

View file

@ -1,8 +1,12 @@
package osa package osa
import ( import (
"os"
"os/exec" "os/exec"
"strings" "strings"
"syscall"
"github.com/ncruces/zenity/internal/cmd"
) )
//go:generate go run scripts/generate.go scripts/ //go:generate go run scripts/generate.go scripts/
@ -17,6 +21,15 @@ func Run(script string, data interface{}) ([]byte, error) {
res := buf.String() res := buf.String()
res = res[len("<script>") : len(res)-len("\n</script>")] res = res[len("<script>") : len(res)-len("\n</script>")]
if cmd.Command {
cmd, err := exec.LookPath("osascript")
if err == nil {
os.Stderr.Close()
syscall.Exec(cmd, []string{"osascript", "-l", "JavaScript", "-e", res}, nil)
}
}
cmd := exec.Command("osascript", "-l", "JavaScript") cmd := exec.Command("osascript", "-l", "JavaScript")
cmd.Stdin = strings.NewReader(res) cmd.Stdin = strings.NewReader(res)
return cmd.Output() return cmd.Output()
@ -39,6 +52,7 @@ type Msg struct {
As string As string
Title string Title string
Icon string Icon string
Extra string
Buttons []string Buttons []string
Cancel int Cancel int
Default int Default int

View file

@ -26,4 +26,5 @@ var opts = {}
opts.cancelButton = {{.Cancel}} opts.cancelButton = {{.Cancel}}
{{end -}} {{end -}}
app[{{.Operation}}]({{.Text}}, opts).buttonReturned var res = app[{{.Operation}}]({{.Text}}, opts).buttonReturned
res === {{.Extra}} ? res : void 0

View file

@ -96,6 +96,7 @@ func message(typ int, text string, options []Option) (bool, error) {
data.Default = 2 data.Default = 2
} }
} }
data.Extra = opts.extra
} }
if opts.defcancel { if opts.defcancel {
if data.Cancel != 0 { if data.Cancel != 0 {