WIP: zenity command (macos).
This commit is contained in:
parent
1fc55eed81
commit
23eb1aabe2
5 changed files with 17 additions and 6 deletions
|
@ -240,7 +240,7 @@ func (f *FileFilters) String() string {
|
|||
func (f *FileFilters) Set(s string) error {
|
||||
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]
|
||||
s = split[1]
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"os/exec"
|
||||
"strings"
|
||||
|
||||
"github.com/ncruces/zenity/internal/cmd"
|
||||
"github.com/ncruces/zenity/internal/osa"
|
||||
)
|
||||
|
||||
|
@ -34,6 +35,7 @@ func SelectFileMutiple(options ...Option) ([]string, error) {
|
|||
Multiple: true,
|
||||
Prompt: opts.title,
|
||||
Location: opts.filename,
|
||||
Separator: cmd.Separator,
|
||||
Type: appleFilters(opts.filters),
|
||||
})
|
||||
if err, ok := err.(*exec.ExitError); ok && err.ExitCode() == 1 {
|
||||
|
@ -48,7 +50,7 @@ func SelectFileMutiple(options ...Option) ([]string, error) {
|
|||
if len(out) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
return strings.Split(string(out), "\x00"), nil
|
||||
return strings.Split(string(out), cmd.Separator), nil
|
||||
}
|
||||
|
||||
func SelectFileSave(options ...Option) (string, error) {
|
||||
|
@ -93,7 +95,16 @@ func appleFilters(filters []FileFilter) []string {
|
|||
var filter []string
|
||||
for _, f := range filters {
|
||||
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
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package cmd
|
||||
|
||||
var Command bool
|
||||
var Separator string
|
||||
var Separator = "\x00"
|
||||
|
|
|
@ -38,9 +38,9 @@ type File struct {
|
|||
Prompt string
|
||||
Name string
|
||||
Location string
|
||||
Separator string
|
||||
Type []string
|
||||
Multiple bool
|
||||
Separator rune
|
||||
}
|
||||
|
||||
type Msg struct {
|
||||
|
|
|
@ -18,7 +18,7 @@ opts.multipleSelectionsAllowed = {{.Multiple}}
|
|||
|
||||
var res = app[{{.Operation}}](opts)
|
||||
if (Array.isArray(res)) {
|
||||
res.join(String.fromCodePoint({{.Separator}}))
|
||||
res.join({{.Separator}})
|
||||
} else {
|
||||
res.toString()
|
||||
}
|
Loading…
Reference in a new issue