zenity/msg.go

61 lines
1.7 KiB
Go
Raw Permalink Normal View History

2020-01-23 06:44:28 -05:00
package zenity
// Question displays the question dialog.
//
2021-03-05 10:14:30 -05:00
// Valid options: Title, Width, Height, OKLabel, CancelLabel, ExtraButton,
2022-06-02 07:24:24 -04:00
// Icon, WindowIcon, Attach, Modal, NoWrap, Ellipsize, DefaultCancel.
2022-03-25 20:58:27 -04:00
//
// May return: ErrCanceled, ErrExtraButton.
2021-04-29 11:05:28 -04:00
func Question(text string, options ...Option) error {
2021-03-04 07:42:30 -05:00
return message(questionKind, text, applyOptions(options))
2020-01-23 06:44:28 -05:00
}
// Info displays the info dialog.
//
2022-06-02 07:24:24 -04:00
// Valid options: Title, Width, Height, OKLabel, ExtraButton,
// Icon, WindowIcon, Attach, Modal, NoWrap, Ellipsize.
2022-03-25 20:58:27 -04:00
//
// May return: ErrCanceled, ErrExtraButton.
2021-04-29 11:05:28 -04:00
func Info(text string, options ...Option) error {
2021-03-04 07:42:30 -05:00
return message(infoKind, text, applyOptions(options))
2020-01-23 06:44:28 -05:00
}
// Warning displays the warning dialog.
//
2022-06-02 07:24:24 -04:00
// Valid options: Title, Width, Height, OKLabel, ExtraButton,
// Icon, WindowIcon, Attach, Modal, NoWrap, Ellipsize.
2022-03-25 20:58:27 -04:00
//
// May return: ErrCanceled, ErrExtraButton.
2021-04-29 11:05:28 -04:00
func Warning(text string, options ...Option) error {
2021-03-04 07:42:30 -05:00
return message(warningKind, text, applyOptions(options))
2020-01-23 06:44:28 -05:00
}
// Error displays the error dialog.
//
2022-06-02 07:24:24 -04:00
// Valid options: Title, Width, Height, OKLabel, ExtraButton,
// Icon, WindowIcon, Attach, Modal, NoWrap, Ellipsize.
2022-03-25 20:58:27 -04:00
//
// May return: ErrCanceled, ErrExtraButton.
2021-04-29 11:05:28 -04:00
func Error(text string, options ...Option) error {
2021-03-04 07:42:30 -05:00
return message(errorKind, text, applyOptions(options))
2020-01-23 06:44:28 -05:00
}
type messageKind int
const (
questionKind messageKind = iota
infoKind
warningKind
errorKind
)
2021-03-03 21:52:05 -05:00
// NoWrap returns an Option to disable enable text wrapping (Unix only).
2020-01-23 06:44:28 -05:00
func NoWrap() Option {
2020-01-24 07:52:45 -05:00
return funcOption(func(o *options) { o.noWrap = true })
2020-01-23 06:44:28 -05:00
}
2021-03-03 21:52:05 -05:00
// Ellipsize returns an Option to enable ellipsizing in the dialog text (Unix only).
2020-01-23 06:44:28 -05:00
func Ellipsize() Option {
2020-01-24 07:52:45 -05:00
return funcOption(func(o *options) { o.ellipsize = true })
2020-01-23 06:44:28 -05:00
}