Added width/height on Unix (fix #2).
This commit is contained in:
parent
f433dd524c
commit
80459ed6ff
4 changed files with 39 additions and 7 deletions
|
@ -29,6 +29,8 @@ var (
|
|||
|
||||
// General options
|
||||
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
|
||||
|
||||
|
|
13
msg.go
13
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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
16
zenity.go
16
zenity.go
|
@ -22,6 +22,8 @@ func (e constError) Error() string { return string(e) }
|
|||
type options struct {
|
||||
// General options
|
||||
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
|
||||
|
||||
|
|
Loading…
Reference in a new issue