Skip to content

Commit

Permalink
fix: getting unsuported formats from clipboard returning unhelpful er…
Browse files Browse the repository at this point in the history
…ror message

ref #983
  • Loading branch information
tomasklaen committed Sep 6, 2024
1 parent a2ea5ac commit 6ef8af5
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/ziggy/commands/clipboard.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package commands

import (
"errors"
"flag"
"fmt"
"strings"
"uosc/bins/src/ziggy/lib"

"github.com/atotto/clipboard"
Expand All @@ -13,8 +15,18 @@ type ClipboardResult struct {
}

func GetClipboard(_ []string) {
// We need to do this instead of just `Payload: lib.Must(clipboard.ReadAll())` because
// the atotto/clipboard returns unhelpful messages like "the operation completed successfully".
payload, err := clipboard.ReadAll()
if err != nil {
if strings.Contains(strings.ToLower(err.Error()), "successfully") {
lib.Check(errors.New("clipboard format not supported"))
}
lib.Check(err)
}

fmt.Print(string(lib.Must(lib.JSONMarshal(ClipboardResult{
Payload: lib.Must(clipboard.ReadAll()),
Payload: payload,
}))))
}

Expand Down

0 comments on commit 6ef8af5

Please sign in to comment.