zenity/msg_darwin.go

43 lines
1 KiB
Go
Raw Normal View History

2020-01-04 22:21:39 -05:00
package zenity
import (
2020-01-19 06:57:05 -05:00
"github.com/ncruces/zenity/internal/zenutil"
2020-01-04 22:21:39 -05:00
)
2021-04-29 11:05:28 -04:00
func message(kind messageKind, text string, opts options) error {
2021-03-04 21:01:59 -05:00
var data zenutil.Dialog
2021-02-19 12:46:47 -05:00
data.Text = text
data.Options.Timeout = zenutil.Timeout
2021-03-03 21:52:05 -05:00
// dialog is more flexible, alert prettier
var dialog bool
2022-05-05 08:04:27 -04:00
if opts.icon != 0 || opts.customIcon != "" { // use if we want to show a specific icon
2021-03-03 21:52:05 -05:00
dialog = true
} else if kind == questionKind && opts.cancelLabel == nil { // use for questions with default buttons
dialog = true
}
2020-01-04 22:21:39 -05:00
2020-01-06 07:01:51 -05:00
if dialog {
2020-01-09 20:46:53 -05:00
data.Operation = "displayDialog"
2021-02-19 12:46:47 -05:00
data.Options.Title = opts.title
2022-05-05 08:04:27 -04:00
if opts.customIcon != "" {
data.IconPath = opts.customIcon
} else {
data.Options.Icon = opts.icon.String()
}
2020-01-04 22:21:39 -05:00
} else {
2020-01-09 20:46:53 -05:00
data.Operation = "displayAlert"
2021-04-06 07:35:22 -04:00
data.Options.As = kind.String()
2021-03-03 21:52:05 -05:00
if opts.title != nil {
data.Text = *opts.title
2021-02-19 12:46:47 -05:00
data.Options.Message = text
2020-01-09 20:46:53 -05:00
}
2020-01-04 22:21:39 -05:00
}
2021-04-06 07:35:22 -04:00
data.SetButtons(getButtons(dialog, kind == questionKind, opts))
2020-01-04 22:21:39 -05:00
2021-03-04 21:01:59 -05:00
out, err := zenutil.Run(opts.ctx, "dialog", data)
2021-04-29 11:05:28 -04:00
_, err = strResult(opts, out, err)
return err
2020-01-04 22:21:39 -05:00
}