WIP: zenity command (macos).

This commit is contained in:
Nuno Cruces 2020-01-09 02:38:10 +00:00
parent 1fc55eed81
commit 23eb1aabe2
5 changed files with 17 additions and 6 deletions

View File

@ -240,7 +240,7 @@ func (f *FileFilters) String() string {
func (f *FileFilters) Set(s string) error { func (f *FileFilters) Set(s string) error {
var filter zenity.FileFilter var filter zenity.FileFilter
if split := strings.SplitN(s, "|", 2); len(split) > 0 { if split := strings.SplitN(s, "|", 2); len(split) > 1 {
filter.Name = split[0] filter.Name = split[0]
s = split[1] s = split[1]
} }

View File

@ -4,6 +4,7 @@ import (
"os/exec" "os/exec"
"strings" "strings"
"github.com/ncruces/zenity/internal/cmd"
"github.com/ncruces/zenity/internal/osa" "github.com/ncruces/zenity/internal/osa"
) )
@ -34,6 +35,7 @@ func SelectFileMutiple(options ...Option) ([]string, error) {
Multiple: true, Multiple: true,
Prompt: opts.title, Prompt: opts.title,
Location: opts.filename, Location: opts.filename,
Separator: cmd.Separator,
Type: appleFilters(opts.filters), Type: appleFilters(opts.filters),
}) })
if err, ok := err.(*exec.ExitError); ok && err.ExitCode() == 1 { if err, ok := err.(*exec.ExitError); ok && err.ExitCode() == 1 {
@ -48,7 +50,7 @@ func SelectFileMutiple(options ...Option) ([]string, error) {
if len(out) == 0 { if len(out) == 0 {
return nil, nil return nil, nil
} }
return strings.Split(string(out), "\x00"), nil return strings.Split(string(out), cmd.Separator), nil
} }
func SelectFileSave(options ...Option) (string, error) { func SelectFileSave(options ...Option) (string, error) {
@ -93,7 +95,16 @@ func appleFilters(filters []FileFilter) []string {
var filter []string var filter []string
for _, f := range filters { for _, f := range filters {
for _, p := range f.Patterns { for _, p := range f.Patterns {
filter = append(filter, p) // FIXME star := strings.LastIndexByte(p, '*')
if star >= 0 {
dot := strings.LastIndexByte(p, '.')
if star > dot {
return nil
}
filter = append(filter, p[dot+1:])
} else {
filter = append(filter, p)
}
} }
} }
return filter return filter

View File

@ -1,4 +1,4 @@
package cmd package cmd
var Command bool var Command bool
var Separator string var Separator = "\x00"

View File

@ -38,9 +38,9 @@ type File struct {
Prompt string Prompt string
Name string Name string
Location string Location string
Separator string
Type []string Type []string
Multiple bool Multiple bool
Separator rune
} }
type Msg struct { type Msg struct {

View File

@ -18,7 +18,7 @@ opts.multipleSelectionsAllowed = {{.Multiple}}
var res = app[{{.Operation}}](opts) var res = app[{{.Operation}}](opts)
if (Array.isArray(res)) { if (Array.isArray(res)) {
res.join(String.fromCodePoint({{.Separator}})) res.join({{.Separator}})
} else { } else {
res.toString() res.toString()
} }