zenity/entry_unix.go

45 lines
1 KiB
Go
Raw Normal View History

2021-03-05 08:56:16 -05:00
// +build !windows,!darwin
package zenity
import (
2021-03-05 21:07:00 -05:00
"strings"
2021-03-05 08:56:16 -05:00
"github.com/ncruces/zenity/internal/zenutil"
)
2021-03-05 21:07:00 -05:00
func entry(text string, opts options) (string, bool, error) {
2021-04-08 11:43:14 -04:00
args := []string{"--entry", "--text", text}
args = appendTitle(args, opts)
args = appendButtons(args, opts)
args = appendWidthHeight(args, opts)
args = appendIcon(args, opts)
if opts.entryText != "" {
args = append(args, "--entry-text", opts.entryText)
2021-03-05 08:56:16 -05:00
}
2021-03-05 10:14:30 -05:00
if opts.hideText {
args = append(args, "--hide-text")
}
2021-03-05 08:56:16 -05:00
out, err := zenutil.Run(opts.ctx, args)
2021-04-08 11:43:14 -04:00
return strResult(opts, out, err)
2021-03-05 21:07:00 -05:00
}
func password(opts options) (string, string, bool, error) {
args := []string{"--password"}
2021-04-08 11:43:14 -04:00
args = appendTitle(args, opts)
args = appendButtons(args, opts)
2021-03-05 21:07:00 -05:00
if opts.username {
args = append(args, "--username")
}
out, err := zenutil.Run(opts.ctx, args)
2021-04-08 11:43:14 -04:00
str, ok, err := strResult(opts, out, err)
if ok && opts.username {
2021-03-05 21:29:00 -05:00
if split := strings.SplitN(string(out), "|", 2); len(split) == 2 {
2021-03-05 21:07:00 -05:00
return split[0], split[1], true, nil
}
}
2021-04-08 11:43:14 -04:00
return "", str, ok, err
2021-03-05 08:56:16 -05:00
}