zenity/msg_darwin.go

55 lines
1.2 KiB
Go
Raw Normal View History

2020-01-04 22:21:39 -05:00
package zenity
import (
2022-05-06 08:48:31 -04:00
"os"
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
2022-06-02 07:49:31 -04:00
if opts.attach != nil {
data.Application = opts.attach
} else if i, ok := opts.windowIcon.(string); ok {
2022-06-01 19:00:08 -04:00
data.WindowIcon = i
}
2021-02-19 12:46:47 -05:00
2021-03-03 21:52:05 -05:00
// dialog is more flexible, alert prettier
var dialog bool
2022-05-17 11:18:12 -04:00
if opts.icon != nil { // 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-17 11:18:12 -04:00
switch i := opts.icon.(type) {
case string:
_, err := os.Stat(i)
2022-05-06 08:48:31 -04:00
if err != nil {
return err
}
2022-05-17 11:18:12 -04:00
data.IconPath = i
case DialogIcon:
data.Options.Icon = i.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
}