zenity/zenity.go

66 lines
1.5 KiB
Go
Raw Normal View History

2020-01-23 06:44:28 -05:00
// Package zenity provides cross-platform access to simple dialogs that interact
// graphically with the user.
//
// It is inspired by, and closely follows the API of, the zenity program, which
// it uses to provide the functionality on various Unixes. See:
//
2020-01-26 11:04:49 -05:00
// https://help.gnome.org/users/zenity/stable/
2020-01-23 06:44:28 -05:00
//
// This package does not require cgo, and it does not impose any threading or
// initialization requirements.
2020-01-04 22:21:39 -05:00
package zenity
2020-01-18 07:40:16 -05:00
import "image/color"
2020-01-06 07:01:51 -05:00
type constError string
func (e constError) Error() string { return string(e) }
2020-01-04 22:21:39 -05:00
type options struct {
// General options
title string
// File selection options
2020-01-24 07:52:45 -05:00
filename string
directory bool
confirmOverwrite bool
confirmCreate bool
showHidden bool
fileFilters []FileFilter
2020-01-04 22:21:39 -05:00
2020-01-18 07:40:16 -05:00
// Color selection options
2020-01-24 07:52:45 -05:00
color color.Color
showPalette bool
2020-01-18 07:40:16 -05:00
2020-01-04 22:21:39 -05:00
// Message options
2020-01-24 07:52:45 -05:00
icon MessageIcon
okLabel string
cancelLabel string
extraButton string
noWrap bool
ellipsize bool
defaultCancel bool
2020-01-04 22:21:39 -05:00
}
2020-01-23 06:44:28 -05:00
// An Option is an argument passed to dialog functions to customize their
// behavior.
2020-01-24 07:52:45 -05:00
type Option interface {
apply(*options)
}
type funcOption func(*options)
func (f funcOption) apply(o *options) { f(o) }
2020-01-04 22:21:39 -05:00
2020-01-24 07:52:45 -05:00
func applyOptions(options []Option) (res options) {
2020-01-04 22:21:39 -05:00
for _, o := range options {
2020-01-24 07:52:45 -05:00
o.apply(&res)
2020-01-04 22:21:39 -05:00
}
return
}
2020-01-23 06:44:28 -05:00
// Title returns an Option to set the dialog title.
2020-01-04 22:21:39 -05:00
func Title(title string) Option {
2020-01-24 07:52:45 -05:00
return funcOption(func(o *options) { o.title = title })
2020-01-04 22:21:39 -05:00
}