forked from ncruces/zenity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
list_darwin.go
60 lines (52 loc) · 1.56 KB
/
list_darwin.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package zenity
import (
"fmt"
"github.com/ncruces/zenity/internal/zenutil"
)
func list(text string, items []string, opts options) (string, error) {
if len(items) == 0 {
return "", fmt.Errorf("%w: empty items list", ErrUnsupported)
}
if opts.extraButton != nil {
return "", fmt.Errorf("%w: extra button", ErrUnsupported)
}
if len(opts.defaultItems) > 1 {
return "", fmt.Errorf("%w: multiple default items", ErrUnsupported)
}
var data zenutil.List
data.Items = items
data.Options.Prompt = &text
data.Options.Title = opts.title
data.Options.OK = opts.okLabel
data.Options.Cancel = opts.cancelLabel
data.Options.Default = opts.defaultItems
data.Options.Empty = !opts.disallowEmpty
if opts.attach != nil {
data.Application = opts.attach
}
if i, ok := opts.windowIcon.(string); ok {
data.WindowIcon = i
}
out, err := zenutil.Run(opts.ctx, "list", data)
return strResult(opts, out, err)
}
func listMultiple(text string, items []string, opts options) ([]string, error) {
if len(items) == 0 {
return nil, fmt.Errorf("%w: empty items list", ErrUnsupported)
}
if opts.extraButton != nil {
return nil, fmt.Errorf("%w: extra button", ErrUnsupported)
}
var data zenutil.List
data.Items = items
data.Options.Prompt = &text
data.Options.Title = opts.title
data.Options.OK = opts.okLabel
data.Options.Cancel = opts.cancelLabel
data.Options.Default = opts.defaultItems
data.Options.Empty = !opts.disallowEmpty
data.Options.Multiple = true
data.Separator = zenutil.Separator
out, err := zenutil.Run(opts.ctx, "list", data)
return lstResult(opts, out, err)
}