zenity/msg.go

85 lines
2.4 KiB
Go
Raw Normal View History

2020-01-23 06:44:28 -05:00
package zenity
// ErrExtraButton is returned by dialog functions when the extra button is
// pressed.
2021-03-03 21:52:05 -05:00
const ErrExtraButton = stringErr("Extra button pressed")
2020-01-23 06:44:28 -05:00
// Question displays the question dialog.
//
// Returns true on OK, false on Cancel, or ErrExtraButton.
//
2021-02-12 09:24:13 -05:00
// Valid options: Title, Width, Height, Icon, OKLabel, CancelLabel,
// ExtraButton, NoWrap, Ellipsize, DefaultCancel.
2020-01-23 06:44:28 -05:00
func Question(text string, options ...Option) (bool, error) {
return message(questionKind, text, options)
}
// Info displays the info dialog.
//
// Returns true on OK, false on dismiss, or ErrExtraButton.
//
2021-02-12 09:24:13 -05:00
// Valid options: Title, Width, Height, Icon, OKLabel, ExtraButton,
// NoWrap, Ellipsize.
2020-01-23 06:44:28 -05:00
func Info(text string, options ...Option) (bool, error) {
return message(infoKind, text, options)
}
// Warning displays the warning dialog.
//
// Returns true on OK, false on dismiss, or ErrExtraButton.
//
2021-02-12 09:24:13 -05:00
// Valid options: Title, Width, Height, Icon, OKLabel, ExtraButton,
// NoWrap, Ellipsize.
2020-01-23 06:44:28 -05:00
func Warning(text string, options ...Option) (bool, error) {
return message(warningKind, text, options)
}
// Error displays the error dialog.
//
// Returns true on OK, false on dismiss, or ErrExtraButton.
//
2021-02-12 09:24:13 -05:00
// Valid options: Title, Width, Height, Icon, OKLabel, ExtraButton,
// NoWrap, Ellipsize.
2020-01-23 06:44:28 -05:00
func Error(text string, options ...Option) (bool, error) {
return message(errorKind, text, options)
}
type messageKind int
const (
questionKind messageKind = iota
infoKind
warningKind
errorKind
)
// OKLabel returns an Option to set the label of the OK button.
func OKLabel(ok string) Option {
2021-03-03 21:52:05 -05:00
return funcOption(func(o *options) { o.okLabel = &ok })
2020-01-23 06:44:28 -05:00
}
// CancelLabel returns an Option to set the label of the Cancel button.
func CancelLabel(cancel string) Option {
2021-03-03 21:52:05 -05:00
return funcOption(func(o *options) { o.cancelLabel = &cancel })
2020-01-23 06:44:28 -05:00
}
// ExtraButton returns an Option to add an extra button.
func ExtraButton(extra string) Option {
2021-03-03 21:52:05 -05:00
return funcOption(func(o *options) { o.extraButton = &extra })
2020-01-23 06:44:28 -05:00
}
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
}
2021-03-03 21:52:05 -05:00
// DefaultCancel returns an Option to give the Cancel button focus by default.
2020-01-23 06:44:28 -05:00
func DefaultCancel() Option {
2020-01-24 07:52:45 -05:00
return funcOption(func(o *options) { o.defaultCancel = true })
2020-01-23 06:44:28 -05:00
}