mirror of
https://github.com/rwinkhart/libmutton.git
synced 2026-09-02 23:27:26 -04:00
Implement unique clipboard clearing behavior for interactive GUI/TUI implementations
This commit is contained in:
+5
-13
@@ -10,8 +10,8 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// copyField copies a field from an entry to the clipboard.
|
||||
func copyField(executableName, copySubject string) {
|
||||
// copyString copies a string to the clipboard.
|
||||
func copyString(continuous bool, copySubject string) {
|
||||
var envSet bool // track whether environment variables are set
|
||||
var cmd *exec.Cmd
|
||||
// determine whether to use wl-copy (Wayland) or xclip (X11)
|
||||
@@ -31,16 +31,8 @@ func copyField(executableName, copySubject string) {
|
||||
os.Exit(ErrorClipboard)
|
||||
}
|
||||
|
||||
// launch clipboard clearing process if executableName is provided
|
||||
if executableName != "" {
|
||||
cmd = exec.Command(executableName, "clipclear")
|
||||
writeToStdin(cmd, copySubject)
|
||||
err = cmd.Start()
|
||||
if err != nil {
|
||||
fmt.Println(AnsiError + "Failed to launch automated clipboard clearing process - Does this libmutton implementation support the \"clipclear\" argument?" + AnsiReset)
|
||||
os.Exit(ErrorClipboard)
|
||||
}
|
||||
Exit(0) // only exit if clipboard clearing process is launched, otherwise assume continuous clipboard refresh
|
||||
if !continuous {
|
||||
launchClipClear(copySubject)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,5 +69,5 @@ func clipClear(oldContents string) {
|
||||
os.Exit(ErrorClipboard)
|
||||
}
|
||||
}
|
||||
os.Exit(0) // use os.Exit instead of core.Exit, as this function runs out of a background subprocess that is invisible to the user (will never appear in GUI/TUI environment)
|
||||
Exit(0)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user