zenity/msg_unix.go

53 lines
1.3 KiB
Go
Raw Permalink Normal View History

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
2020-01-09 06:17:39 -05:00
import (
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
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")
}
2021-04-08 11:43:14 -04:00
args = appendTitle(args, opts)
args = appendButtons(args, opts)
args = appendWidthHeight(args, opts)
args = appendIcon(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
}
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
}