WIP: zenity command (macos).
This commit is contained in:
parent
7fe6837b4f
commit
ec8eb571eb
9 changed files with 47 additions and 4 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -13,5 +13,3 @@
|
|||
|
||||
# Dependency directories (remove the comment below to include it)
|
||||
# vendor/
|
||||
|
||||
osa_gen_darwin.go
|
|
@ -1 +1 @@
|
|||
# Zenity for Golang
|
||||
# Zenity dialogs for Golang, Windows and macOS
|
1
cmd/zenity/.gitignore
vendored
Normal file
1
cmd/zenity/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
zenity
|
24
cmd/zenity/main.go
Normal file
24
cmd/zenity/main.go
Normal 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
3
internal/cmd/cmd.go
Normal file
|
@ -0,0 +1,3 @@
|
|||
package cmd
|
||||
|
||||
var Command bool
|
1
internal/osa/.gitignore
vendored
Normal file
1
internal/osa/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
osa_gen_darwin.go
|
|
@ -1,8 +1,12 @@
|
|||
package osa
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"github.com/ncruces/zenity/internal/cmd"
|
||||
)
|
||||
|
||||
//go:generate go run scripts/generate.go scripts/
|
||||
|
@ -17,6 +21,15 @@ func Run(script string, data interface{}) ([]byte, error) {
|
|||
|
||||
res := buf.String()
|
||||
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.Stdin = strings.NewReader(res)
|
||||
return cmd.Output()
|
||||
|
@ -39,6 +52,7 @@ type Msg struct {
|
|||
As string
|
||||
Title string
|
||||
Icon string
|
||||
Extra string
|
||||
Buttons []string
|
||||
Cancel int
|
||||
Default int
|
||||
|
|
|
@ -26,4 +26,5 @@ var opts = {}
|
|||
opts.cancelButton = {{.Cancel}}
|
||||
{{end -}}
|
||||
|
||||
app[{{.Operation}}]({{.Text}}, opts).buttonReturned
|
||||
var res = app[{{.Operation}}]({{.Text}}, opts).buttonReturned
|
||||
res === {{.Extra}} ? res : void 0
|
|
@ -96,6 +96,7 @@ func message(typ int, text string, options []Option) (bool, error) {
|
|||
data.Default = 2
|
||||
}
|
||||
}
|
||||
data.Extra = opts.extra
|
||||
}
|
||||
if opts.defcancel {
|
||||
if data.Cancel != 0 {
|
||||
|
|
Loading…
Reference in a new issue