Documentation ¶
Overview ¶
Package gozenity is a simple wrapper for zenity) in Go.
Index ¶
- func Calendar(prompt string, defaultDate time.Time) (date string, err error)
- func ColorSelection(prompt, initial string, showPalette bool) (color string, err error)
- func DirectorySelection(prompt string) (files []string, err error)
- func Entry(prompt, placeholder string) (entry string, err error)
- func Error(prompt string) (err error)
- func FileSelection(prompt string, filtersMap map[string][]string) (files []string, err error)
- func Info(prompt string) (err error)
- func List(prompt string, options ...string) (selection string, err error)
- func Notification(prompt string) (err error)
- func Password(prompt string) (password string, err error)
- func Progress(prompt string, progress <-chan int) (err error)
- func Question(prompt string) (answer bool, err error)
- func Scale(prompt string, args *ScaleArgs) (answer int, err error)
- func TextInfo(prompt string, args *TextInfoArgs) (text string, err error)
- func UsernameAndPassword(prompt string) (password, username string, err error)
- func Warning(prompt string) (err error)
- type EmptySelectionError
- type Gozenity
- type ScaleArgs
- type TextInfoArgs
Examples ¶
- Calendar
- ColorSelection
- ColorSelection (Second)
- DirectorySelection
- Entry
- Error
- FileSelection
- FileSelection (Second)
- Info
- List
- Password
- Progress
- Question
- Scale
- TextInfo
- TextInfo (Fifth)
- TextInfo (Fourth)
- TextInfo (Second)
- TextInfo (Seventh)
- TextInfo (Sixth)
- TextInfo (Third)
- UsernameAndPassword
- Warning
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Calendar ¶
Calendar picks a date
Example ¶
package main import ( "fmt" "time" "git.sr.ht/~jcmuller/gozenity" ) func main() { args := time.Now() entry, err := gozenity.Calendar("Please select 4/12/2018", args) if err != nil { panic(err) } fmt.Println(entry) }
Output: 04/12/2018
func ColorSelection ¶
ColorSelection pops up a color selection dialog
Example ¶
package main import ( "fmt" "git.sr.ht/~jcmuller/gozenity" ) func main() { color, err := gozenity.ColorSelection("Choose green:", "green", false) if err != nil { panic(err) } fmt.Println(color) }
Output: rgb(0,128,0)
Example (Second) ¶
package main import ( "fmt" "git.sr.ht/~jcmuller/gozenity" ) func main() { color, err := gozenity.ColorSelection("Choose green:", "green", true) if err != nil { panic(err) } fmt.Println(color) }
Output: rgb(0,128,0)
func DirectorySelection ¶
DirectorySelection opens a file selector
Example ¶
package main import ( "fmt" "strings" "git.sr.ht/~jcmuller/gozenity" ) func main() { dirs, err := gozenity.DirectorySelection("Choose that guy") if err != nil { panic(err) } fmt.Println(strings.Join(dirs, " ")) }
Output: dir1 dir2
func Entry ¶
Entry asks for input
Example ¶
package main import ( "fmt" "git.sr.ht/~jcmuller/gozenity" ) func main() { entry, err := gozenity.Entry("Please type an answer (expecting 'Foo'):", "Placeholder") if err != nil { panic(err) } fmt.Println(entry) }
Output: Foo
func Error ¶
Error errors errors
Example ¶
package main import ( "git.sr.ht/~jcmuller/gozenity" ) func main() { err := gozenity.Error("Something turrible happened :(.") if err != nil { panic(err) } }
Output:
func FileSelection ¶
FileSelection opens a file selector
Example ¶
package main import ( "fmt" "strings" "git.sr.ht/~jcmuller/gozenity" ) func main() { files, err := gozenity.FileSelection("Choose that guy", nil) if err != nil { panic(err) } fmt.Println(strings.Join(files, " ")) }
Output: file1 file2
Example (Second) ¶
package main import ( "fmt" "strings" "git.sr.ht/~jcmuller/gozenity" ) func main() { filters := map[string][]string{ `Go files`: {`*.go`}, `Markdown files`: {`*.md`, `*.markdown`}, } files, err := gozenity.FileSelection("Choose that guy", filters) if err != nil { panic(err) } fmt.Println(strings.Join(files, " ")) }
Output: file1 file2
func Info ¶
Info informs information
Example ¶
package main import ( "git.sr.ht/~jcmuller/gozenity" ) func main() { gozenity.Info("This thing happened.") }
Output:
func List ¶
List pops up the menu
Example ¶
package main import ( "fmt" "git.sr.ht/~jcmuller/gozenity" ) func main() { output, err := gozenity.List( "Choose an option:", "One word", "Two", "Three things", ) if err != nil { if err, ok := err.(*gozenity.EmptySelectionError); !ok { fmt.Println(fmt.Errorf("Error getting output: %s", err)) } } fmt.Println(output) }
Output: Two
func Password ¶
Password asks for a password
Example ¶
package main import ( "fmt" "git.sr.ht/~jcmuller/gozenity" ) func main() { password, err := gozenity.Password("Enter password:") if err != nil { panic(err) } fmt.Println(password) }
Output: hunter2
func Progress ¶
Progress shows a pogress bar modal
Example ¶
package main import ( "time" "git.sr.ht/~jcmuller/gozenity" ) func main() { progress := make(chan int) go gozenity.Progress("We're doing that", progress) for i := 0; i <= 100; i++ { progress <- i time.Sleep(time.Millisecond * 50) } }
Output:
func Question ¶
Question asks for answer
Example ¶
package main import ( "fmt" "git.sr.ht/~jcmuller/gozenity" ) func main() { answer, err := gozenity.Question("Who? Answer 'her'.") if err != nil { panic(err) } fmt.Println(answer) }
Output: true
func Scale ¶
Scale shows a nice scale
Example ¶
package main import ( "fmt" "git.sr.ht/~jcmuller/gozenity" ) func main() { val, err := gozenity.Scale( "Select a value", &gozenity.ScaleArgs{Initial: 30, Max: 100}, ) if err != nil { panic(err) } fmt.Println(val) }
Output: 23
func TextInfo ¶
func TextInfo(prompt string, args *TextInfoArgs) (text string, err error)
TextInfo shows a webview
Example ¶
package main import ( "fmt" "git.sr.ht/~jcmuller/gozenity" ) func main() { args := &gozenity.TextInfoArgs{ Editable: true, } _, err := gozenity.TextInfo("Do something here:", args) if err != nil { fmt.Println(err) } }
Output: One of Filename, Text or URL need to be supplied
Example (Fifth) ¶
package main import ( "fmt" "io/ioutil" "log" "os" "git.sr.ht/~jcmuller/gozenity" ) func main() { tmpfile, err := ioutil.TempFile("", "filenametext") if err != nil { log.Fatal(err) } defer os.Remove(tmpfile.Name()) // clean up if _, err = tmpfile.WriteString("Hello, world!"); err != nil { log.Fatal(err) } if err := tmpfile.Close(); err != nil { log.Fatal(err) } args := &gozenity.TextInfoArgs{ Editable: true, Filename: tmpfile.Name(), } string, err := gozenity.TextInfo("Do something here:", args) if err != nil { panic(err) } fmt.Println(string) }
Output: Hello, world!
Example (Fourth) ¶
package main import ( "fmt" "git.sr.ht/~jcmuller/gozenity" ) func main() { args := &gozenity.TextInfoArgs{ Editable: true, URL: `https://google.com`, } string, err := gozenity.TextInfo("Do something here:", args) if err != nil { panic(err) } fmt.Println(string) }
Output:
Example (Second) ¶
package main import ( "fmt" "git.sr.ht/~jcmuller/gozenity" ) func main() { args := &gozenity.TextInfoArgs{ Editable: true, Text: `Hello, worldly worlded world.`, } string, err := gozenity.TextInfo("Do something here:", args) if err != nil { panic(err) } fmt.Println(string) }
Output: Hello, worldly worlded world.
Example (Seventh) ¶
package main import ( "fmt" "git.sr.ht/~jcmuller/gozenity" ) func main() { args := &gozenity.TextInfoArgs{ Editable: true, Text: `Hello, worldly worlded world.`, URL: "https://goobar.com", } _, err := gozenity.TextInfo("Do something here:", args) if err != nil { fmt.Println(err) } }
Output: Only one of Filename, Text and URL can be supplied
Example (Sixth) ¶
package main import ( "fmt" "git.sr.ht/~jcmuller/gozenity" ) func main() { args := &gozenity.TextInfoArgs{ Editable: true, Filename: "/tmp/foobar.txt", } _, err := gozenity.TextInfo("Do something here:", args) fmt.Println(err) }
Output: stat /tmp/foobar.txt: no such file or directory
Example (Third) ¶
package main import ( "fmt" "git.sr.ht/~jcmuller/gozenity" ) func main() { args := &gozenity.TextInfoArgs{ Checkbox: "Agree?", Editable: true, Text: `Hello, worldly worlded world.`, } string, err := gozenity.TextInfo("Do something here:", args) if err != nil { panic(err) } fmt.Println(string) }
Output: Hello, worldly worlded world.
func UsernameAndPassword ¶
UsernameAndPassword asks for a username and password
Example ¶
package main import ( "fmt" "git.sr.ht/~jcmuller/gozenity" ) func main() { password, username, err := gozenity.UsernameAndPassword("Enter password:") if err != nil { panic(err) } fmt.Printf("%s\n%s\n", username, password) }
Output: user hunter2
Types ¶
type EmptySelectionError ¶
type EmptySelectionError struct{}
EmptySelectionError is returned if there is no selection
func (*EmptySelectionError) Error ¶
func (e *EmptySelectionError) Error() string
type Gozenity ¶
type Gozenity struct {
// contains filtered or unexported fields
}
Gozenity holds the structure of this thing
type TextInfoArgs ¶
TextInfoArgs represents options for text info
func (*TextInfoArgs) Parse ¶
func (tia *TextInfoArgs) Parse() (args []string, err error)
Parse returns a slice of strings usable for a text info