diff --git a/cmd/zenity/main.go b/cmd/zenity/main.go index a31fb58..262c43e 100644 --- a/cmd/zenity/main.go +++ b/cmd/zenity/main.go @@ -474,8 +474,10 @@ func lstResult(l []string, err error) { if err != nil { errResult(err) } - os.Stdout.WriteString(strings.Join(l, zenutil.Separator)) - os.Stdout.WriteString(zenutil.LineBreak) + if len(l) > 0 { + os.Stdout.WriteString(strings.Join(l, zenutil.Separator)) + os.Stdout.WriteString(zenutil.LineBreak) + } os.Exit(0) } diff --git a/internal/zenutil/osa_generated.go b/internal/zenutil/osa_generated.go index ed15e73..f931ead 100644 --- a/internal/zenutil/osa_generated.go +++ b/internal/zenutil/osa_generated.go @@ -42,7 +42,7 @@ if(Array.isArray(res)){res.join({{json .Separator}})}else{res.toString()} var app=Application.currentApplication() app.includeStandardAdditions=true var res=app.chooseFromList({{json .Items}},{{json .Options}}) -res.join({{json .Separator}}) +if(res.length!==0)res.join({{json .Separator}}) {{- end}} {{define "notify" -}} var app=Application.currentApplication() diff --git a/internal/zenutil/osascripts/list.gojs b/internal/zenutil/osascripts/list.gojs index 060c48f..df174dc 100644 --- a/internal/zenutil/osascripts/list.gojs +++ b/internal/zenutil/osascripts/list.gojs @@ -2,4 +2,4 @@ var app = Application.currentApplication() app.includeStandardAdditions = true var res = app.chooseFromList({{json .Items}}, {{json .Options}}) -res.join({{json .Separator}}) \ No newline at end of file +if (res.length !== 0) res.join({{json .Separator}}) \ No newline at end of file diff --git a/util_unix.go b/util_unix.go index 3723927..c83d119 100644 --- a/util_unix.go +++ b/util_unix.go @@ -71,8 +71,11 @@ func strResult(opts options, out []byte, err error) (string, error) { func lstResult(opts options, out []byte, err error) ([]string, error) { str, err := strResult(opts, out, err) - if err == nil { - return strings.Split(str, zenutil.Separator), nil + if err != nil { + return nil, err } - return nil, err + if len(out) == 0 { + return []string{}, nil + } + return strings.Split(str, zenutil.Separator), nil } diff --git a/util_unix_test.go b/util_unix_test.go index bce27b6..323a3e3 100644 --- a/util_unix_test.go +++ b/util_unix_test.go @@ -98,6 +98,9 @@ func Test_lstResult(t *testing.T) { sentinel := errors.New("sentinel") cancel := exec.Command("false").Run() + if out, err := lstResult(options{}, []byte(""), nil); !reflect.DeepEqual(out, []string{}) || err != nil { + t.Errorf(`lstResult("out", nil) = %v, %v`, out, err) + } if out, err := lstResult(options{}, []byte("out"), nil); !reflect.DeepEqual(out, []string{"out"}) || err != nil { t.Errorf(`lstResult("out", nil) = %v, %v`, out, err) }