From 80459ed6ffdda46789357a4f5a7fafc1fd055373 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20N=C3=BCtzi?= Date: Fri, 12 Feb 2021 15:24:13 +0100 Subject: [PATCH] Added width/height on Unix (fix #2). --- cmd/zenity/main.go | 8 +++++++- msg.go | 13 ++++++++----- msg_unix.go | 7 +++++++ zenity.go | 18 +++++++++++++++++- 4 files changed, 39 insertions(+), 7 deletions(-) diff --git a/cmd/zenity/main.go b/cmd/zenity/main.go index 0e6f379..2d7b552 100644 --- a/cmd/zenity/main.go +++ b/cmd/zenity/main.go @@ -28,7 +28,9 @@ var ( colorSelectionDlg bool // General options - title string + title string + width uint + height uint // Message options text string @@ -122,6 +124,8 @@ func setupFlags() { // General options flag.StringVar(&title, "title", "", "Set the dialog title") flag.StringVar(&icon, "window-icon", "", "Set the window icon (error, info, question, warning)") + flag.UintVar(&width, "width", 0, "Set the width") + flag.UintVar(&height, "height", 0, "Set the height") // Message options flag.StringVar(&text, "text", "", "Set the dialog text") @@ -192,6 +196,8 @@ func loadFlags() []zenity.Option { // General options opts = append(opts, zenity.Title(title)) + opts = append(opts, zenity.Width(width)) + opts = append(opts, zenity.Height(height)) // Message options diff --git a/msg.go b/msg.go index 383c3e4..6f7884c 100644 --- a/msg.go +++ b/msg.go @@ -8,8 +8,8 @@ const ErrExtraButton = constError("Extra button pressed") // // Returns true on OK, false on Cancel, or ErrExtraButton. // -// Valid options: Title, Icon, OKLabel, CancelLabel, ExtraButton, NoWrap, -// Ellipsize, DefaultCancel. +// Valid options: Title, Width, Height, Icon, OKLabel, CancelLabel, +// ExtraButton, NoWrap, Ellipsize, DefaultCancel. func Question(text string, options ...Option) (bool, error) { return message(questionKind, text, options) } @@ -18,7 +18,8 @@ func Question(text string, options ...Option) (bool, error) { // // Returns true on OK, false on dismiss, or ErrExtraButton. // -// Valid options: Title, Icon, OKLabel, ExtraButton, NoWrap, Ellipsize. +// Valid options: Title, Width, Height, Icon, OKLabel, ExtraButton, +// NoWrap, Ellipsize. func Info(text string, options ...Option) (bool, error) { return message(infoKind, text, options) } @@ -27,7 +28,8 @@ func Info(text string, options ...Option) (bool, error) { // // Returns true on OK, false on dismiss, or ErrExtraButton. // -// Valid options: Title, Icon, OKLabel, ExtraButton, NoWrap, Ellipsize. +// Valid options: Title, Width, Height, Icon, OKLabel, ExtraButton, +// NoWrap, Ellipsize. func Warning(text string, options ...Option) (bool, error) { return message(warningKind, text, options) } @@ -36,7 +38,8 @@ func Warning(text string, options ...Option) (bool, error) { // // Returns true on OK, false on dismiss, or ErrExtraButton. // -// Valid options: Title, Icon, OKLabel, ExtraButton, NoWrap, Ellipsize. +// Valid options: Title, Width, Height, Icon, OKLabel, ExtraButton, +// NoWrap, Ellipsize. func Error(text string, options ...Option) (bool, error) { return message(errorKind, text, options) } diff --git a/msg_unix.go b/msg_unix.go index c29e1ca..eba957e 100644 --- a/msg_unix.go +++ b/msg_unix.go @@ -4,6 +4,7 @@ package zenity import ( "os/exec" + "strconv" "github.com/ncruces/zenity/internal/zenutil" ) @@ -28,6 +29,12 @@ func message(kind messageKind, text string, options []Option) (bool, error) { if opts.title != "" { args = append(args, "--title", opts.title) } + if opts.width > 0 { + args = append(args, "--width", strconv.FormatUint(uint64(opts.width), 10)) + } + if opts.height > 0 { + args = append(args, "--height", strconv.FormatUint(uint64(opts.height), 10)) + } if opts.okLabel != "" { args = append(args, "--ok-label", opts.okLabel) } diff --git a/zenity.go b/zenity.go index 764bb5b..373a643 100644 --- a/zenity.go +++ b/zenity.go @@ -21,7 +21,9 @@ func (e constError) Error() string { return string(e) } type options struct { // General options - title string + title string + width uint + height uint // File selection options filename string @@ -70,6 +72,20 @@ func Title(title string) Option { return funcOption(func(o *options) { o.title = title }) } +// Width returns an Option to set the dialog width (Unix only). +func Width(width uint) Option { + return funcOption(func(o *options) { + o.width = width + }) +} + +// Height returns an Option to set the dialog height (Unix only). +func Height(height uint) Option { + return funcOption(func(o *options) { + o.height = height + }) +} + // DialogIcon is the enumeration for dialog icons. type DialogIcon int