Command improvements.

This commit is contained in:
Nuno Cruces 2022-03-26 02:56:06 +00:00
parent 781b9e4fa1
commit 05bce67856
4 changed files with 28 additions and 20 deletions

View file

@ -316,22 +316,18 @@ func loadFlags() []zenity.Option {
switch { switch {
case errorDlg: case errorDlg:
setDefault(&title, "Error") setDefault(&title, "Error")
setDefault(&icon, "dialog-error")
setDefault(&text, "An error has occurred.") setDefault(&text, "An error has occurred.")
setDefault(&okLabel, "OK") setDefault(&okLabel, "OK")
case infoDlg: case infoDlg:
setDefault(&title, "Information") setDefault(&title, "Information")
setDefault(&icon, "dialog-information")
setDefault(&text, "All updates are complete.") setDefault(&text, "All updates are complete.")
setDefault(&okLabel, "OK") setDefault(&okLabel, "OK")
case warningDlg: case warningDlg:
setDefault(&title, "Warning") setDefault(&title, "Warning")
setDefault(&icon, "dialog-warning")
setDefault(&text, "Are you sure you want to proceed?") setDefault(&text, "Are you sure you want to proceed?")
setDefault(&okLabel, "OK") setDefault(&okLabel, "OK")
case questionDlg: case questionDlg:
setDefault(&title, "Question") setDefault(&title, "Question")
setDefault(&icon, "dialog-question")
setDefault(&text, "Are you sure you want to proceed?") setDefault(&text, "Are you sure you want to proceed?")
setDefault(&okLabel, "Yes") setDefault(&okLabel, "Yes")
setDefault(&cancelLabel, "No") setDefault(&cancelLabel, "No")
@ -347,7 +343,6 @@ func loadFlags() []zenity.Option {
setDefault(&cancelLabel, "Cancel") setDefault(&cancelLabel, "Cancel")
case passwordDlg: case passwordDlg:
setDefault(&title, "Type your password") setDefault(&title, "Type your password")
setDefault(&icon, "dialog-password")
setDefault(&okLabel, "OK") setDefault(&okLabel, "OK")
setDefault(&cancelLabel, "Cancel") setDefault(&cancelLabel, "Cancel")
case progressDlg: case progressDlg:
@ -355,10 +350,6 @@ func loadFlags() []zenity.Option {
setDefault(&text, "Running...") setDefault(&text, "Running...")
setDefault(&okLabel, "OK") setDefault(&okLabel, "OK")
setDefault(&cancelLabel, "Cancel") setDefault(&cancelLabel, "Cancel")
case notification:
setDefault(&icon, "dialog-information")
default:
setDefault(&text, "")
} }
// General options // General options
@ -390,10 +381,12 @@ func loadFlags() []zenity.Option {
ico = zenity.WarningIcon ico = zenity.WarningIcon
case "dialog-password": case "dialog-password":
ico = zenity.PasswordIcon ico = zenity.PasswordIcon
case "": default:
ico = zenity.NoIcon ico = zenity.NoIcon
} }
if icon != unspecified {
opts = append(opts, ico) opts = append(opts, ico)
}
// Message options // Message options

View file

@ -14,11 +14,14 @@ import (
func notify(opts ...zenity.Option) error { func notify(opts ...zenity.Option) error {
if !listen { if !listen {
if text == unspecified {
return nil
}
return zenity.Notify(text, opts...) return zenity.Notify(text, opts...)
} }
zenutil.Command = false zenutil.Command = false
icon := zenity.InfoIcon ico := zenity.NoIcon
for scanner := bufio.NewScanner(os.Stdin); scanner.Scan(); { for scanner := bufio.NewScanner(os.Stdin); scanner.Scan(); {
line := scanner.Text() line := scanner.Text()
var cmd, msg string var cmd, msg string
@ -32,20 +35,20 @@ func notify(opts ...zenity.Option) error {
case "icon": case "icon":
switch msg { switch msg {
case "error", "dialog-error": case "error", "dialog-error":
icon = zenity.ErrorIcon ico = zenity.ErrorIcon
case "info", "dialog-information": case "info", "dialog-information":
icon = zenity.InfoIcon ico = zenity.InfoIcon
case "question", "dialog-question": case "question", "dialog-question":
icon = zenity.QuestionIcon ico = zenity.QuestionIcon
case "important", "warning", "dialog-warning": case "important", "warning", "dialog-warning":
icon = zenity.WarningIcon ico = zenity.WarningIcon
case "dialog-password": case "dialog-password":
icon = zenity.PasswordIcon ico = zenity.PasswordIcon
default: default:
icon = zenity.NoIcon ico = zenity.NoIcon
} }
case "message", "tooltip": case "message", "tooltip":
opts := []zenity.Option{icon} opts := []zenity.Option{ico}
if n := strings.IndexByte(msg, '\n'); n >= 0 { if n := strings.IndexByte(msg, '\n'); n >= 0 {
opts = append(opts, zenity.Title(msg[:n])) opts = append(opts, zenity.Title(msg[:n]))
msg = msg[n+1:] msg = msg[n+1:]

View file

@ -32,6 +32,17 @@ func message(kind messageKind, text string, opts options) error {
flags |= 0x30 // MB_ICONWARNING flags |= 0x30 // MB_ICONWARNING
case InfoIcon: case InfoIcon:
flags |= 0x40 // MB_ICONINFORMATION flags |= 0x40 // MB_ICONINFORMATION
case unspecifiedIcon:
switch kind {
case errorKind:
flags |= 0x10 // MB_ICONERROR
case questionKind:
flags |= 0x20 // MB_ICONQUESTION
case warningKind:
flags |= 0x30 // MB_ICONWARNING
case infoKind:
flags |= 0x40 // MB_ICONINFORMATION
}
} }
if kind == questionKind && opts.defaultCancel { if kind == questionKind && opts.defaultCancel {

View file

@ -132,7 +132,8 @@ func (i DialogIcon) apply(o *options) { o.icon = i }
// The stock dialog icons. // The stock dialog icons.
const ( const (
ErrorIcon DialogIcon = iota + 1 unspecifiedIcon DialogIcon = iota
ErrorIcon
WarningIcon WarningIcon
InfoIcon InfoIcon
QuestionIcon QuestionIcon