Attach, modal (unix).
This commit is contained in:
parent
ab7621bec9
commit
69c05cdd0d
21 changed files with 65 additions and 36 deletions
2
color.go
2
color.go
|
@ -4,7 +4,7 @@ import "image/color"
|
|||
|
||||
// SelectColor displays the color selection dialog.
|
||||
//
|
||||
// Valid options: Title, Color, ShowPalette.
|
||||
// Valid options: Title, WindowIcon, Attach, Modal, Color, ShowPalette.
|
||||
//
|
||||
// May return: ErrCanceled.
|
||||
func SelectColor(options ...Option) (color.Color, error) {
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
func selectColor(opts options) (color.Color, error) {
|
||||
args := []string{"--color-selection"}
|
||||
|
||||
args = appendTitle(args, opts)
|
||||
args = appendGeneral(args, opts)
|
||||
if opts.color != nil {
|
||||
args = append(args, "--color", zenutil.UnparseColor(opts.color))
|
||||
}
|
||||
|
|
2
date.go
2
date.go
|
@ -5,7 +5,7 @@ import "time"
|
|||
// Calendar displays the calendar dialog.
|
||||
//
|
||||
// Valid options: Title, Width, Height, OKLabel, CancelLabel, ExtraButton,
|
||||
// Icon, DefaultDate.
|
||||
// WindowIcon, Attach, Modal, DefaultDate.
|
||||
//
|
||||
// May return: ErrCanceled, ErrExtraButton.
|
||||
func Calendar(text string, options ...Option) (time.Time, error) {
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
|
||||
func calendar(text string, opts options) (time.Time, error) {
|
||||
args := []string{"--calendar", "--text", text, "--date-format", zenutil.DateFormat}
|
||||
args = appendTitle(args, opts)
|
||||
args = appendGeneral(args, opts)
|
||||
args = appendButtons(args, opts)
|
||||
args = appendWidthHeight(args, opts)
|
||||
args = appendWindowIcon(args, opts)
|
||||
|
|
2
entry.go
2
entry.go
|
@ -3,7 +3,7 @@ package zenity
|
|||
// Entry displays the text entry dialog.
|
||||
//
|
||||
// Valid options: Title, Width, Height, OKLabel, CancelLabel, ExtraButton,
|
||||
// Icon, EntryText, HideText.
|
||||
// WindowIcon, Attach, Modal, EntryText, HideText.
|
||||
//
|
||||
// May return: ErrCanceled, ErrExtraButton.
|
||||
func Entry(text string, options ...Option) (string, error) {
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
|
||||
func entry(text string, opts options) (string, error) {
|
||||
args := []string{"--entry", "--text", text}
|
||||
args = appendTitle(args, opts)
|
||||
args = appendGeneral(args, opts)
|
||||
args = appendButtons(args, opts)
|
||||
args = appendWidthHeight(args, opts)
|
||||
args = appendWindowIcon(args, opts)
|
||||
|
|
10
file.go
10
file.go
|
@ -8,7 +8,8 @@ import (
|
|||
|
||||
// SelectFile displays the file selection dialog.
|
||||
//
|
||||
// Valid options: Title, Directory, Filename, ShowHidden, FileFilter(s).
|
||||
// Valid options: Title, WindowIcon, Attach, Modal, Directory, Filename,
|
||||
// ShowHidden, FileFilter(s).
|
||||
//
|
||||
// May return: ErrCanceled.
|
||||
func SelectFile(options ...Option) (string, error) {
|
||||
|
@ -17,7 +18,8 @@ func SelectFile(options ...Option) (string, error) {
|
|||
|
||||
// SelectFileMultiple displays the multiple file selection dialog.
|
||||
//
|
||||
// Valid options: Title, Directory, Filename, ShowHidden, FileFilter(s).
|
||||
// Valid options: Title, WindowIcon, Attach, Modal, Directory, Filename,
|
||||
// ShowHidden, FileFilter(s).
|
||||
//
|
||||
// May return: ErrCanceled, ErrUnsupported.
|
||||
func SelectFileMultiple(options ...Option) ([]string, error) {
|
||||
|
@ -31,8 +33,8 @@ func SelectFileMutiple(options ...Option) ([]string, error) {
|
|||
|
||||
// SelectFileSave displays the save file selection dialog.
|
||||
//
|
||||
// Valid options: Title, Filename, ConfirmOverwrite, ConfirmCreate, ShowHidden,
|
||||
// FileFilter(s).
|
||||
// Valid options: Title, WindowIcon, Attach, Modal, Filename,
|
||||
// ConfirmOverwrite, ConfirmCreate, ShowHidden, FileFilter(s).
|
||||
//
|
||||
// May return: ErrCanceled.
|
||||
func SelectFileSave(options ...Option) (string, error) {
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
|
||||
func selectFile(opts options) (string, error) {
|
||||
args := []string{"--file-selection"}
|
||||
args = appendTitle(args, opts)
|
||||
args = appendGeneral(args, opts)
|
||||
args = appendFileArgs(args, opts)
|
||||
|
||||
out, err := zenutil.Run(opts.ctx, args)
|
||||
|
@ -19,7 +19,7 @@ func selectFile(opts options) (string, error) {
|
|||
|
||||
func selectFileMultiple(opts options) ([]string, error) {
|
||||
args := []string{"--file-selection", "--multiple", "--separator", zenutil.Separator}
|
||||
args = appendTitle(args, opts)
|
||||
args = appendGeneral(args, opts)
|
||||
args = appendFileArgs(args, opts)
|
||||
|
||||
out, err := zenutil.Run(opts.ctx, args)
|
||||
|
@ -28,7 +28,7 @@ func selectFileMultiple(opts options) ([]string, error) {
|
|||
|
||||
func selectFileSave(opts options) (string, error) {
|
||||
args := []string{"--file-selection", "--save"}
|
||||
args = appendTitle(args, opts)
|
||||
args = appendGeneral(args, opts)
|
||||
args = appendFileArgs(args, opts)
|
||||
|
||||
out, err := zenutil.Run(opts.ctx, args)
|
||||
|
|
4
list.go
4
list.go
|
@ -3,7 +3,7 @@ package zenity
|
|||
// List displays the list dialog.
|
||||
//
|
||||
// Valid options: Title, Width, Height, OKLabel, CancelLabel, ExtraButton,
|
||||
// Icon, DefaultItems, DisallowEmpty.
|
||||
// WindowIcon, Attach, Modal, DefaultItems, DisallowEmpty.
|
||||
//
|
||||
// May return: ErrCanceled, ErrExtraButton, ErrUnsupported.
|
||||
func List(text string, items []string, options ...Option) (string, error) {
|
||||
|
@ -20,7 +20,7 @@ func ListItems(text string, items ...string) (string, error) {
|
|||
// ListMultiple displays the list dialog, allowing multiple items to be selected.
|
||||
//
|
||||
// Valid options: Title, Width, Height, OKLabel, CancelLabel, ExtraButton,
|
||||
// Icon, DefaultItems, DisallowEmpty.
|
||||
// WindowIcon, Attach, Modal, DefaultItems, DisallowEmpty.
|
||||
//
|
||||
// May return: ErrCanceled, ErrExtraButton, ErrUnsupported.
|
||||
func ListMultiple(text string, items []string, options ...Option) ([]string, error) {
|
||||
|
|
|
@ -6,7 +6,7 @@ import "github.com/ncruces/zenity/internal/zenutil"
|
|||
|
||||
func list(text string, items []string, opts options) (string, error) {
|
||||
args := []string{"--list", "--column=", "--hide-header", "--text", text}
|
||||
args = appendTitle(args, opts)
|
||||
args = appendGeneral(args, opts)
|
||||
args = appendButtons(args, opts)
|
||||
args = appendWidthHeight(args, opts)
|
||||
args = appendWindowIcon(args, opts)
|
||||
|
@ -18,7 +18,7 @@ func list(text string, items []string, opts options) (string, error) {
|
|||
|
||||
func listMultiple(text string, items []string, opts options) ([]string, error) {
|
||||
args := []string{"--list", "--column=", "--hide-header", "--text", text, "--multiple", "--separator", zenutil.Separator}
|
||||
args = appendTitle(args, opts)
|
||||
args = appendGeneral(args, opts)
|
||||
args = appendButtons(args, opts)
|
||||
args = appendWidthHeight(args, opts)
|
||||
args = appendWindowIcon(args, opts)
|
||||
|
|
14
msg.go
14
msg.go
|
@ -3,7 +3,7 @@ package zenity
|
|||
// Question displays the question dialog.
|
||||
//
|
||||
// Valid options: Title, Width, Height, OKLabel, CancelLabel, ExtraButton,
|
||||
// Icon, NoWrap, Ellipsize, DefaultCancel.
|
||||
// Icon, WindowIcon, Attach, Modal, NoWrap, Ellipsize, DefaultCancel.
|
||||
//
|
||||
// May return: ErrCanceled, ErrExtraButton.
|
||||
func Question(text string, options ...Option) error {
|
||||
|
@ -12,8 +12,8 @@ func Question(text string, options ...Option) error {
|
|||
|
||||
// Info displays the info dialog.
|
||||
//
|
||||
// Valid options: Title, Width, Height, OKLabel, ExtraButton, Icon,
|
||||
// NoWrap, Ellipsize.
|
||||
// Valid options: Title, Width, Height, OKLabel, ExtraButton,
|
||||
// Icon, WindowIcon, Attach, Modal, NoWrap, Ellipsize.
|
||||
//
|
||||
// May return: ErrCanceled, ErrExtraButton.
|
||||
func Info(text string, options ...Option) error {
|
||||
|
@ -22,8 +22,8 @@ func Info(text string, options ...Option) error {
|
|||
|
||||
// Warning displays the warning dialog.
|
||||
//
|
||||
// Valid options: Title, Width, Height, OKLabel, ExtraButton, Icon,
|
||||
// NoWrap, Ellipsize.
|
||||
// Valid options: Title, Width, Height, OKLabel, ExtraButton,
|
||||
// Icon, WindowIcon, Attach, Modal, NoWrap, Ellipsize.
|
||||
//
|
||||
// May return: ErrCanceled, ErrExtraButton.
|
||||
func Warning(text string, options ...Option) error {
|
||||
|
@ -32,8 +32,8 @@ func Warning(text string, options ...Option) error {
|
|||
|
||||
// Error displays the error dialog.
|
||||
//
|
||||
// Valid options: Title, Width, Height, OKLabel, ExtraButton, Icon,
|
||||
// NoWrap, Ellipsize.
|
||||
// Valid options: Title, Width, Height, OKLabel, ExtraButton,
|
||||
// Icon, WindowIcon, Attach, Modal, NoWrap, Ellipsize.
|
||||
//
|
||||
// May return: ErrCanceled, ErrExtraButton.
|
||||
func Error(text string, options ...Option) error {
|
||||
|
|
|
@ -16,7 +16,7 @@ func message(kind messageKind, text string, opts options) error {
|
|||
case errorKind:
|
||||
args = append(args, "--error")
|
||||
}
|
||||
args = appendTitle(args, opts)
|
||||
args = appendGeneral(args, opts)
|
||||
args = appendButtons(args, opts)
|
||||
args = appendWidthHeight(args, opts)
|
||||
args = appendWindowIcon(args, opts)
|
||||
|
|
|
@ -6,7 +6,7 @@ import "github.com/ncruces/zenity/internal/zenutil"
|
|||
|
||||
func notify(text string, opts options) error {
|
||||
args := []string{"--notification", "--text", text}
|
||||
args = appendTitle(args, opts)
|
||||
args = appendGeneral(args, opts)
|
||||
switch opts.icon {
|
||||
case ErrorIcon:
|
||||
args = append(args, "--window-icon=dialog-error")
|
||||
|
|
|
@ -3,7 +3,7 @@ package zenity
|
|||
// Progress displays the progress indication dialog.
|
||||
//
|
||||
// Valid options: Title, Width, Height, OKLabel, CancelLabel, ExtraButton,
|
||||
// Icon, MaxValue, Pulsate, NoCancel, TimeRemaining.
|
||||
// Icon, WindowIcon, Attach, Modal, MaxValue, Pulsate, NoCancel, TimeRemaining.
|
||||
//
|
||||
// May return: ErrUnsupported.
|
||||
func Progress(options ...Option) (ProgressDialog, error) {
|
||||
|
|
|
@ -6,7 +6,7 @@ import "github.com/ncruces/zenity/internal/zenutil"
|
|||
|
||||
func progress(opts options) (ProgressDialog, error) {
|
||||
args := []string{"--progress"}
|
||||
args = appendTitle(args, opts)
|
||||
args = appendGeneral(args, opts)
|
||||
args = appendButtons(args, opts)
|
||||
args = appendWidthHeight(args, opts)
|
||||
args = appendWindowIcon(args, opts)
|
||||
|
|
3
pwd.go
3
pwd.go
|
@ -2,7 +2,8 @@ package zenity
|
|||
|
||||
// Password displays the password dialog.
|
||||
//
|
||||
// Valid options: Title, OKLabel, CancelLabel, ExtraButton, Icon, Username.
|
||||
// Valid options: Title, OKLabel, CancelLabel, ExtraButton,
|
||||
// WindowIcon, Attach, Modal, Username.
|
||||
//
|
||||
// May return: ErrCanceled, ErrExtraButton.
|
||||
func Password(options ...Option) (usr string, pwd string, err error) {
|
||||
|
|
|
@ -6,7 +6,7 @@ import "github.com/ncruces/zenity/internal/zenutil"
|
|||
|
||||
func password(opts options) (string, string, error) {
|
||||
args := []string{"--password"}
|
||||
args = appendTitle(args, opts)
|
||||
args = appendGeneral(args, opts)
|
||||
args = appendButtons(args, opts)
|
||||
if opts.username {
|
||||
args = append(args, "--username")
|
||||
|
|
|
@ -4,6 +4,7 @@ package zenity
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
@ -11,10 +12,16 @@ import (
|
|||
"github.com/ncruces/zenity/internal/zenutil"
|
||||
)
|
||||
|
||||
func appendTitle(args []string, opts options) []string {
|
||||
func appendGeneral(args []string, opts options) []string {
|
||||
if opts.title != nil {
|
||||
args = append(args, "--title", *opts.title)
|
||||
}
|
||||
if opts.attach != nil {
|
||||
args = append(args, "--attach", fmt.Sprint(opts.attach))
|
||||
}
|
||||
if opts.modal {
|
||||
args = append(args, "--modal")
|
||||
}
|
||||
return args
|
||||
}
|
||||
|
||||
|
|
|
@ -11,9 +11,13 @@ import (
|
|||
"github.com/ncruces/zenity/internal/zenutil"
|
||||
)
|
||||
|
||||
func Test_appendTitle(t *testing.T) {
|
||||
got := appendTitle(nil, options{title: stringPtr("Title")})
|
||||
want := []string{"--title", "Title"}
|
||||
func Test_appendGeneral(t *testing.T) {
|
||||
got := appendGeneral(nil, options{
|
||||
title: stringPtr("Title"),
|
||||
attach: 12345,
|
||||
modal: true,
|
||||
})
|
||||
want := []string{"--title", "Title", "--attach", "12345", "--modal"}
|
||||
if !reflect.DeepEqual(got, want) {
|
||||
t.Errorf("appendTitle() = %v; want %v", got, want)
|
||||
}
|
||||
|
|
16
zenity.go
16
zenity.go
|
@ -44,6 +44,8 @@ type options struct {
|
|||
defaultCancel bool
|
||||
icon any
|
||||
windowIcon any
|
||||
attach any
|
||||
modal bool
|
||||
|
||||
// Message options
|
||||
noWrap bool
|
||||
|
@ -169,7 +171,7 @@ func Icon(icon any) Option {
|
|||
return funcOption(func(o *options) { o.icon = icon })
|
||||
}
|
||||
|
||||
// WindowIcon returns an Option to set the dialog icon (macOS and Unix only).
|
||||
// WindowIcon returns an Option to set the window icon.
|
||||
//
|
||||
// WindowIcon accepts a DialogIcon, or a string path.
|
||||
func WindowIcon(icon any) Option {
|
||||
|
@ -182,13 +184,23 @@ func WindowIcon(icon any) Option {
|
|||
return funcOption(func(o *options) { o.windowIcon = icon })
|
||||
}
|
||||
|
||||
// CustomIcon returns an Option to set a custom dialog icon, loaded from a file.
|
||||
// CustomIcon returns an Option to set a custom dialog icon.
|
||||
//
|
||||
// Deprecated: use Icon instead.
|
||||
func CustomIcon(path string) Option {
|
||||
return Icon(path)
|
||||
}
|
||||
|
||||
// Attach returns an Option to set the parent window to attach to.
|
||||
func Attach(id any) Option {
|
||||
return funcOption(func(o *options) { o.attach = id })
|
||||
}
|
||||
|
||||
// Modal returns an Option to set the modal hint.
|
||||
func Modal() Option {
|
||||
return funcOption(func(o *options) { o.modal = true })
|
||||
}
|
||||
|
||||
// Context returns an Option to set a Context that can dismiss the dialog.
|
||||
//
|
||||
// Dialogs dismissed by ctx return ctx.Err().
|
||||
|
|
|
@ -27,6 +27,9 @@ func Test_applyOptions(t *testing.T) {
|
|||
{name: "WindowIcon", args: WindowIcon("error"), want: options{windowIcon: "error"}},
|
||||
{name: "Icon", args: Icon(ErrorIcon), want: options{icon: ErrorIcon}},
|
||||
{name: "Icon", args: Icon("error"), want: options{icon: "error"}},
|
||||
{name: "Attach", args: Attach(12345), want: options{attach: 12345}},
|
||||
{name: "Attach", args: Attach("Terminal"), want: options{attach: "Terminal"}},
|
||||
{name: "Modal", args: Modal(), want: options{modal: true}},
|
||||
|
||||
// Message options
|
||||
{name: "NoWrap", args: NoWrap(), want: options{noWrap: true}},
|
||||
|
|
Loading…
Reference in a new issue