2021-03-04 21:01:59 -05:00
|
|
|
package zenity
|
|
|
|
|
|
|
|
import (
|
2022-05-06 08:48:31 -04:00
|
|
|
"os"
|
|
|
|
|
2021-03-04 21:01:59 -05:00
|
|
|
"github.com/ncruces/zenity/internal/zenutil"
|
|
|
|
)
|
|
|
|
|
2021-04-29 11:05:28 -04:00
|
|
|
func entry(text string, opts options) (string, 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
|
2022-06-02 07:49:31 -04:00
|
|
|
if opts.attach != nil {
|
|
|
|
data.Application = opts.attach
|
|
|
|
} else if i, ok := opts.windowIcon.(string); ok {
|
2022-06-01 19:00:08 -04:00
|
|
|
data.WindowIcon = i
|
|
|
|
}
|
2022-05-17 11:18:12 -04:00
|
|
|
switch i := opts.icon.(type) {
|
|
|
|
case string:
|
|
|
|
_, err := os.Stat(i)
|
2022-05-06 08:48:31 -04:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
2022-05-17 11:18:12 -04:00
|
|
|
data.IconPath = i
|
|
|
|
case DialogIcon:
|
|
|
|
data.Options.Icon = i.String()
|
2022-05-05 08:21:00 -04:00
|
|
|
}
|
2021-04-06 07:35:22 -04:00
|
|
|
data.SetButtons(getButtons(true, true, opts))
|
2021-03-04 21:01:59 -05:00
|
|
|
|
|
|
|
out, err := zenutil.Run(opts.ctx, "dialog", data)
|
2021-04-08 11:43:14 -04:00
|
|
|
return strResult(opts, out, err)
|
2021-03-05 21:07:00 -05:00
|
|
|
}
|