commit d0890778335106124e3f23fa69a61c61a4e952c2
parent 05f24270d8d68a37f64f304e082e75f4c89416b9
Author: Sean Enck <sean@ttypty.com>
Date: Sun, 18 Dec 2022 11:53:09 -0500
allow for osc fully
Diffstat:
5 files changed, 51 insertions(+), 30 deletions(-)
diff --git a/cmd/main.go b/cmd/main.go
@@ -313,10 +313,10 @@ func clearClipboard(args []string) error {
if err != nil {
return err
}
- if clipboard.IsInternal() {
+ pCmd, pArgs, valid := clipboard.Args(false)
+ if !valid {
return nil
}
- pCmd, pArgs := clipboard.Args(false)
val = strings.TrimSpace(val)
for idx < clipboard.MaxTime {
idx++
diff --git a/internal/inputs/env.go b/internal/inputs/env.go
@@ -39,7 +39,7 @@ const (
ClipPasteEnv = clipBaseEnv + "PASTE"
// ClipCopyEnv allows overriding the clipboard copy command
ClipCopyEnv = clipBaseEnv + "COPY"
- clipOSCEnv = clipBaseEnv + "OSC"
+ clipOSC52Env = clipBaseEnv + "OSC52"
isYes = "yes"
isNo = "no"
defaultTOTPField = "totp"
@@ -201,8 +201,9 @@ func isYesNoEnv(defaultValue bool, env string) (bool, error) {
return false, fmt.Errorf("invalid yes/no env value for %s", env)
}
-func IsClipOSC() (bool, error) {
- return isYesNoEnv(false, clipOSCEnv)
+// IsClipOSC52 indicates if OSC52 mode is enabled
+func IsClipOSC52() (bool, error) {
+ return isYesNoEnv(false, clipOSC52Env)
}
// IsNoTOTP indicates if TOTP is disabled
@@ -290,6 +291,6 @@ func ListEnvironmentVariables(showValues bool) []string {
results = append(results, e.formatEnvironmentVariable(false, PlatformEnv, detectedValue, "override the detected platform", []string{MacOSPlatform, LinuxWaylandPlatform, LinuxXPlatform, WindowsLinuxPlatform}))
results = append(results, e.formatEnvironmentVariable(false, noTOTPEnv, isNo, "disable TOTP integrations", isYesNoArgs))
results = append(results, e.formatEnvironmentVariable(false, HookDirEnv, "", "the path to hooks to execute on actions against the database", []string{"directory"}))
- results = append(results, e.formatEnvironmentVariable(false, clipOSCEnv, isNo, "enable OSC52 clipboard mode", isYesNoArgs))
+ results = append(results, e.formatEnvironmentVariable(false, clipOSC52Env, isNo, "enable OSC52 clipboard mode", isYesNoArgs))
return results
}
diff --git a/internal/inputs/env_test.go b/internal/inputs/env_test.go
@@ -107,6 +107,10 @@ func TestIsReadOnly(t *testing.T) {
checkYesNo("LOCKBOX_READONLY", t, inputs.IsReadOnly, false)
}
+func TestIsOSC52(t *testing.T) {
+ checkYesNo("LOCKBOX_CLIP_OSC52", t, inputs.IsClipOSC52, false)
+}
+
func TestIsNoTOTP(t *testing.T) {
checkYesNo("LOCKBOX_NOTOTP", t, inputs.IsNoTOTP, false)
}
diff --git a/internal/platform/clipboard.go b/internal/platform/clipboard.go
@@ -23,10 +23,6 @@ type (
}
)
-func (c Clipboard) IsInternal() bool {
- return c.isInternal
-}
-
func newClipboard(copying, pasting []string) (Clipboard, error) {
max, err := inputs.GetClipboardMax()
if err != nil {
@@ -63,7 +59,7 @@ func NewClipboard() (Clipboard, error) {
if overrideCopy != nil && overridePaste != nil {
return newClipboard(overrideCopy, overridePaste)
}
- isOSC, err := inputs.IsClipOSC()
+ isOSC, err := inputs.IsClipOSC52()
if err != nil {
return Clipboard{}, err
}
@@ -109,21 +105,24 @@ func (c Clipboard) CopyTo(value string) error {
osc.Copy(value)
return nil
}
- exe, err := os.Executable()
- if err != nil {
- return err
- }
- cmd, args := c.Args(true)
+ cmd, args, _ := c.Args(true)
pipeTo(cmd, value, true, args...)
if value != "" {
fmt.Printf("clipboard will clear in %d seconds\n", c.MaxTime)
+ exe, err := os.Executable()
+ if err != nil {
+ return err
+ }
pipeTo(exe, value, false, "clear")
}
return nil
}
// Args returns clipboard args for execution.
-func (c Clipboard) Args(copying bool) (string, []string) {
+func (c Clipboard) Args(copying bool) (string, []string, bool) {
+ if c.isInternal {
+ return "", []string{}, false
+ }
var using []string
if copying {
using = c.copying
@@ -134,7 +133,7 @@ func (c Clipboard) Args(copying bool) (string, []string) {
if len(using) > 1 {
args = using[1:]
}
- return using[0], args
+ return using[0], args, true
}
func pipeTo(command, value string, wait bool, args ...string) error {
diff --git a/internal/platform/clipboard_test.go b/internal/platform/clipboard_test.go
@@ -9,6 +9,7 @@ import (
)
func TestNoClipboard(t *testing.T) {
+ os.Setenv("LOCKBOX_CLIP_OSC52", "no")
os.Setenv("LOCKBOX_CLIP_MAX", "")
os.Setenv("LOCKBOX_NOCLIP", "yes")
_, err := platform.NewClipboard()
@@ -19,6 +20,7 @@ func TestNoClipboard(t *testing.T) {
func TestMaxTime(t *testing.T) {
os.Setenv("LOCKBOX_NOCLIP", "no")
+ os.Setenv("LOCKBOX_CLIP_OSC52", "no")
os.Setenv("LOCKBOX_PLATFORM", string(platform.LinuxWayland))
os.Setenv("LOCKBOX_CLIP_MAX", "")
c, err := platform.NewClipboard()
@@ -51,6 +53,7 @@ func TestMaxTime(t *testing.T) {
func TestClipboardInstances(t *testing.T) {
os.Setenv("LOCKBOX_NOCLIP", "no")
os.Setenv("LOCKBOX_CLIP_MAX", "")
+ os.Setenv("LOCKBOX_CLIP_OSC52", "no")
for _, item := range []platform.System{platform.MacOS, platform.LinuxWayland, platform.LinuxX, platform.WindowsLinux} {
os.Setenv("LOCKBOX_PLATFORM", string(item))
_, err := platform.NewClipboard()
@@ -60,37 +63,51 @@ func TestClipboardInstances(t *testing.T) {
}
}
+func TestOSC52(t *testing.T) {
+ os.Setenv("LOCKBOX_CLIP_OSC52", "yes")
+ c, _ := platform.NewClipboard()
+ _, _, ok := c.Args(true)
+ if ok {
+ t.Error("invalid clipboard, should be an internal call")
+ }
+ _, _, ok = c.Args(false)
+ if ok {
+ t.Error("invalid clipboard, should be an internal call")
+ }
+}
+
func TestArgsOverride(t *testing.T) {
os.Setenv("LOCKBOX_CLIP_PASTE", "abc xyz 111")
+ os.Setenv("LOCKBOX_CLIP_OSC52", "no")
os.Setenv("LOCKBOX_PLATFORM", string(platform.WindowsLinux))
c, _ := platform.NewClipboard()
- cmd, args := c.Args(true)
- if cmd != "clip.exe" || len(args) != 0 {
+ cmd, args, ok := c.Args(true)
+ if cmd != "clip.exe" || len(args) != 0 || !ok {
t.Error("invalid parse")
}
- cmd, args = c.Args(false)
- if cmd != "abc" || len(args) != 2 || args[0] != "xyz" || args[1] != "111" {
+ cmd, args, ok = c.Args(false)
+ if cmd != "abc" || len(args) != 2 || args[0] != "xyz" || args[1] != "111" || !ok {
t.Error("invalid parse")
}
os.Setenv("LOCKBOX_CLIP_COPY", "zzz lll 123")
c, _ = platform.NewClipboard()
- cmd, args = c.Args(true)
- if cmd != "zzz" || len(args) != 2 || args[0] != "lll" || args[1] != "123" {
+ cmd, args, ok = c.Args(true)
+ if cmd != "zzz" || len(args) != 2 || args[0] != "lll" || args[1] != "123" || !ok {
t.Error("invalid parse")
}
- cmd, args = c.Args(false)
- if cmd != "abc" || len(args) != 2 || args[0] != "xyz" || args[1] != "111" {
+ cmd, args, ok = c.Args(false)
+ if cmd != "abc" || len(args) != 2 || args[0] != "xyz" || args[1] != "111" || !ok {
t.Error("invalid parse")
}
os.Setenv("LOCKBOX_CLIP_PASTE", "")
os.Setenv("LOCKBOX_CLIP_COPY", "")
c, _ = platform.NewClipboard()
- cmd, args = c.Args(true)
- if cmd != "clip.exe" || len(args) != 0 {
+ cmd, args, ok = c.Args(true)
+ if cmd != "clip.exe" || len(args) != 0 || !ok {
t.Error("invalid parse")
}
- cmd, args = c.Args(false)
- if cmd != "powershell.exe" || len(args) != 2 || args[0] != "-command" || args[1] != "Get-Clipboard" {
+ cmd, args, ok = c.Args(false)
+ if cmd != "powershell.exe" || len(args) != 2 || args[0] != "-command" || args[1] != "Get-Clipboard" || !ok {
fmt.Println(args)
t.Error("invalid parse")
}