-
-
Notifications
You must be signed in to change notification settings - Fork 37
/
msg_darwin.go
55 lines (48 loc) · 1.2 KB
/
msg_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
package zenity
import (
"os"
"github.com/ncruces/zenity/internal/zenutil"
)
func message(kind messageKind, text string, opts options) error {
var data zenutil.Dialog
data.Text = text
data.Options.Timeout = zenutil.Timeout
if opts.attach != nil {
data.Application = opts.attach
}
if i, ok := opts.windowIcon.(string); ok {
data.WindowIcon = i
}
// dialog is more flexible, alert prettier
var dialog bool
if opts.icon != nil { // use if we want to show a specific icon
dialog = true
} else if kind == questionKind && opts.cancelLabel == nil { // use for questions with default buttons
dialog = true
}
if dialog {
data.Operation = "displayDialog"
data.Options.Title = opts.title
switch i := opts.icon.(type) {
case string:
_, err := os.Stat(i)
if err != nil {
return err
}
data.IconPath = i
case DialogIcon:
data.Options.Icon = i.String()
}
} else {
data.Operation = "displayAlert"
data.Options.As = kind.String()
if opts.title != nil {
data.Text = *opts.title
data.Options.Message = text
}
}
data.SetButtons(getButtons(dialog, kind == questionKind, opts))
out, err := zenutil.Run(opts.ctx, "dialog", data)
_, err = strResult(opts, out, err)
return err
}