zenity/entry_darwin.go

41 lines
999 B
Go
Raw Normal View History

2021-03-04 21:01:59 -05:00
package zenity
import (
2021-03-05 21:29:00 -05:00
"bytes"
2021-03-04 21:01:59 -05:00
"os/exec"
"github.com/ncruces/zenity/internal/zenutil"
)
2021-03-05 21:07:00 -05:00
func entry(text string, opts options) (string, bool, error) {
2021-03-04 21:01:59 -05:00
var data zenutil.Dialog
data.Text = text
data.Operation = "displayDialog"
data.Options.Title = opts.title
data.Options.Answer = &opts.entryText
data.Options.Hidden = opts.hideText
data.Options.Timeout = zenutil.Timeout
2021-04-06 07:35:22 -04:00
data.Options.Icon = opts.icon.String()
data.SetButtons(getButtons(true, true, opts))
2021-03-04 21:01:59 -05:00
out, err := zenutil.Run(opts.ctx, "dialog", data)
2021-03-05 21:29:00 -05:00
out = bytes.TrimSuffix(out, []byte{'\n'})
2021-03-04 21:01:59 -05:00
if err, ok := err.(*exec.ExitError); ok && err.ExitCode() == 1 {
2021-03-05 21:29:00 -05:00
if opts.extraButton != nil &&
*opts.extraButton == string(out) {
2021-03-05 21:07:00 -05:00
return "", false, ErrExtraButton
2021-03-04 21:01:59 -05:00
}
2021-03-05 21:07:00 -05:00
return "", false, nil
2021-03-04 21:01:59 -05:00
}
if err != nil {
2021-03-05 21:07:00 -05:00
return "", false, err
2021-03-04 21:01:59 -05:00
}
2021-03-05 21:29:00 -05:00
return string(out), true, nil
2021-03-05 21:07:00 -05:00
}
func password(opts options) (string, string, bool, error) {
opts.hideText = true
2021-03-29 14:07:44 -04:00
pass, ok, err := entry("Password:", opts)
2021-03-05 21:07:00 -05:00
return "", pass, ok, err
2021-03-04 21:01:59 -05:00
}