2022-03-24 10:37:37 -04:00
|
|
|
//go:build !windows && !darwin
|
2020-01-08 13:12:29 -05:00
|
|
|
|
2020-01-04 22:21:39 -05:00
|
|
|
package zenity
|
|
|
|
|
2022-05-11 12:49:15 -04:00
|
|
|
import "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-05 08:56:16 -05:00
|
|
|
args := []string{"--text", text, "--no-markup"}
|
2020-01-23 06:44:28 -05:00
|
|
|
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")
|
|
|
|
}
|
2022-06-02 07:24:24 -04:00
|
|
|
args = appendGeneral(args, opts)
|
2021-04-08 11:43:14 -04:00
|
|
|
args = appendButtons(args, opts)
|
|
|
|
args = appendWidthHeight(args, opts)
|
2022-05-18 09:48:09 -04:00
|
|
|
args = appendWindowIcon(args, opts)
|
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:
|
2021-04-08 11:43:14 -04:00
|
|
|
args = append(args, "--icon-name=dialog-error")
|
2020-01-12 18:09:11 -05:00
|
|
|
case WarningIcon:
|
2021-04-08 11:43:14 -04:00
|
|
|
args = append(args, "--icon-name=dialog-warning")
|
2020-01-04 22:21:39 -05:00
|
|
|
case InfoIcon:
|
2021-04-08 11:43:14 -04:00
|
|
|
args = append(args, "--icon-name=dialog-information")
|
2020-01-04 22:21:39 -05:00
|
|
|
case QuestionIcon:
|
2021-04-08 11:43:14 -04:00
|
|
|
args = append(args, "--icon-name=dialog-question")
|
2021-03-05 10:14:30 -05:00
|
|
|
case PasswordIcon:
|
|
|
|
args = append(args, "--icon-name=dialog-password")
|
|
|
|
case NoIcon:
|
|
|
|
args = append(args, "--icon-name=")
|
2020-01-04 22:21:39 -05:00
|
|
|
}
|
2022-05-24 07:02:51 -04:00
|
|
|
if i, ok := opts.icon.(string); ok {
|
|
|
|
args = append(args, "--icon-name", i)
|
|
|
|
}
|
2020-01-04 22:21:39 -05:00
|
|
|
|
2020-01-28 07:46:43 -05:00
|
|
|
out, err := zenutil.Run(opts.ctx, args)
|
2021-04-29 11:05:28 -04:00
|
|
|
_, err = strResult(opts, out, err)
|
|
|
|
return err
|
2020-01-04 22:21:39 -05:00
|
|
|
}
|