Implement initial clipboard functionality for Wayland

This commit is contained in:
2024-03-01 22:36:10 -05:00
parent b17a3ae372
commit 4bd44e7b44
2 changed files with 23 additions and 10 deletions
+12 -6
View File
@@ -48,24 +48,26 @@ func main() {
} else if argsCount == 3 { } else if argsCount == 3 {
// declare entry field to perform target operation on // declare entry field to perform target operation on
var field rune
switch args[1] { switch args[1] {
case "copy": case "copy":
var field uint8
switch args[2] { switch args[2] {
case "password", "-p": case "password", "-p":
field = 'p' field = 0
case "username", "-u": case "username", "-u":
field = 'u' field = 1
case "url", "-l": case "url", "-l":
field = 'l' field = 2
case "note", "-n": case "note", "-n":
field = 'n' field = 3
default: default:
cli.HelpCopy() cli.HelpCopy()
} }
offline.CopyField(targetLocation, field) offline.CopyField(targetLocation, field)
case "edit": case "edit":
var field rune
field = field // TODO temporary to avoid unused variable error
switch args[2] { switch args[2] {
case "password", "-p": case "password", "-p":
field = 'p' field = 'p'
@@ -79,8 +81,10 @@ func main() {
default: default:
cli.HelpCopy() cli.HelpCopy()
} }
offline.CopyField(targetLocation, field) // TODO offline.EditEntry(targetLocation, field), exit after run
case "add": case "add":
var field rune
field = field // TODO temporary to avoid unused variable error
switch args[2] { switch args[2] {
case "password", "-p": case "password", "-p":
field = 'p' field = 'p'
@@ -92,6 +96,8 @@ func main() {
} }
// TODO offline.AddEntry(targetLocation, field), exit after run // TODO offline.AddEntry(targetLocation, field), exit after run
case "gen": case "gen":
var field rune
field = field // TODO temporary to avoid unused variable error
switch args[2] { switch args[2] {
case "update", "-u": // TODO offline.GenUpdate(targetLocation), exit after run case "update", "-u": // TODO offline.GenUpdate(targetLocation), exit after run
default: default:
+11 -4
View File
@@ -2,14 +2,21 @@ package offline
import ( import (
"fmt" "fmt"
"io"
"os" "os"
"os/exec"
) )
func CopyField(targetLocation string, field rune) { func CopyField(targetLocation string, field uint8) {
if isFile, _ := TargetIsFile(targetLocation, true); isFile { if isFile, _ := TargetIsFile(targetLocation, true); isFile {
//decryptedEntry := DecryptGPG(targetLocation) copySubject := DecryptGPG(targetLocation)[field]
// TODO implement clipboard support (maybe use third-party library?) cmd := exec.Command("wl-copy")
fmt.Println("In the future, this will copy " + string(field)) stdin, _ := cmd.StdinPipe()
go func() {
defer stdin.Close()
io.WriteString(stdin, copySubject)
}()
cmd.Run()
} else { } else {
fmt.Println(AnsiError + "Failed to read \"" + targetLocation + "\" - it is a directory" + AnsiReset) fmt.Println(AnsiError + "Failed to read \"" + targetLocation + "\" - it is a directory" + AnsiReset)
} }