2020-01-08 13:12:29 -05:00
|
|
|
// +build !windows,!darwin
|
|
|
|
|
2020-01-04 22:21:39 -05:00
|
|
|
package zenity
|
|
|
|
|
2020-01-09 06:17:39 -05:00
|
|
|
import (
|
|
|
|
"os/exec"
|
|
|
|
|
2020-01-19 06:57:05 -05:00
|
|
|
"github.com/ncruces/zenity/internal/zenutil"
|
2020-01-09 06:17:39 -05:00
|
|
|
)
|
2020-01-04 22:21:39 -05:00
|
|
|
|
2020-01-23 06:44:28 -05:00
|
|
|
func message(kind messageKind, text string, options []Option) (bool, error) {
|
2020-01-24 07:52:45 -05:00
|
|
|
opts := applyOptions(options)
|
2020-01-04 22:21:39 -05:00
|
|
|
|
2020-01-23 06:44:28 -05:00
|
|
|
var args []string
|
|
|
|
switch kind {
|
|
|
|
case questionKind:
|
|
|
|
args = append(args, "--question")
|
|
|
|
case infoKind:
|
|
|
|
args = append(args, "--info")
|
|
|
|
case warningKind:
|
|
|
|
args = append(args, "--warning")
|
|
|
|
case errorKind:
|
|
|
|
args = append(args, "--error")
|
|
|
|
}
|
2020-01-09 06:17:39 -05:00
|
|
|
if text != "" {
|
|
|
|
args = append(args, "--text", text, "--no-markup")
|
|
|
|
}
|
2020-01-04 22:21:39 -05:00
|
|
|
if opts.title != "" {
|
|
|
|
args = append(args, "--title", opts.title)
|
|
|
|
}
|
2020-01-24 07:52:45 -05:00
|
|
|
if opts.okLabel != "" {
|
|
|
|
args = append(args, "--ok-label", opts.okLabel)
|
2020-01-04 22:21:39 -05:00
|
|
|
}
|
2020-01-24 07:52:45 -05:00
|
|
|
if opts.cancelLabel != "" {
|
|
|
|
args = append(args, "--cancel-label", opts.cancelLabel)
|
2020-01-04 22:21:39 -05:00
|
|
|
}
|
2020-01-24 07:52:45 -05:00
|
|
|
if opts.extraButton != "" {
|
|
|
|
args = append(args, "--extra-button", opts.extraButton)
|
2020-01-04 22:21:39 -05:00
|
|
|
}
|
2020-01-24 07:52:45 -05:00
|
|
|
if opts.noWrap {
|
2020-01-04 22:21:39 -05:00
|
|
|
args = append(args, "--no-wrap")
|
|
|
|
}
|
|
|
|
if opts.ellipsize {
|
|
|
|
args = append(args, "--ellipsize")
|
|
|
|
}
|
2020-01-24 07:52:45 -05:00
|
|
|
if opts.defaultCancel {
|
2020-01-04 22:21:39 -05:00
|
|
|
args = append(args, "--default-cancel")
|
|
|
|
}
|
|
|
|
switch opts.icon {
|
|
|
|
case ErrorIcon:
|
|
|
|
args = append(args, "--icon-name=dialog-error")
|
2020-01-12 18:09:11 -05:00
|
|
|
case WarningIcon:
|
|
|
|
args = append(args, "--icon-name=dialog-warning")
|
2020-01-04 22:21:39 -05:00
|
|
|
case InfoIcon:
|
|
|
|
args = append(args, "--icon-name=dialog-information")
|
|
|
|
case QuestionIcon:
|
|
|
|
args = append(args, "--icon-name=dialog-question")
|
|
|
|
}
|
|
|
|
|
2020-01-19 06:57:05 -05:00
|
|
|
out, err := zenutil.Run(args)
|
2020-01-06 07:35:45 -05:00
|
|
|
if err, ok := err.(*exec.ExitError); ok && err.ExitCode() != 255 {
|
2020-01-24 07:52:45 -05:00
|
|
|
if len(out) > 0 && string(out[:len(out)-1]) == opts.extraButton {
|
2020-01-06 07:35:45 -05:00
|
|
|
return false, ErrExtraButton
|
|
|
|
}
|
2020-01-04 22:21:39 -05:00
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
return true, err
|
|
|
|
}
|