Fix complex strings failing to copy on Windows

This commit is contained in:
2024-03-11 15:09:30 -04:00
parent c7735d32be
commit 5cee48d412
4 changed files with 11 additions and 9 deletions
+4 -2
View File
@@ -8,5 +8,7 @@ var ConfigDir = home + "/.config/libmutton"
var ConfigPath = ConfigDir + "/libmutton.ini"
// PathSeparator defines the character used to separate directories in a path (platform-specific)
const PathSeparator = "/"
const Windows = false // TODO temporary, remove after native sync is implemented
const (
PathSeparator = "/"
Windows = false // TODO temporary, remove after native sync is implemented
)
+4 -2
View File
@@ -8,5 +8,7 @@ var ConfigDir = home + "\\AppData\\Local\\libmutton"
var ConfigPath = ConfigDir + "\\libmutton.ini"
// PathSeparator defines the character used to separate directories in a path (platform-specific)
const PathSeparator = "\\"
const Windows = true // TODO temporary, remove after native sync is implemented
const (
PathSeparator = "\\"
Windows = true // TODO temporary, remove after native sync is implemented
)
+1 -1
View File
@@ -12,7 +12,7 @@ import (
// CopyField copies a field from an entry to the clipboard
func copyField(copySubject string, executableName string) {
cmd := exec.Command("powershell.exe", "-c", fmt.Sprintf("echo '%s' | Set-Clipboard", copySubject))
cmd := exec.Command("powershell.exe", "-c", fmt.Sprintf("echo '%s' | Set-Clipboard", strings.ReplaceAll(copySubject, "'", "''")))
err := cmd.Run()
if err != nil {
fmt.Println(AnsiError + "Failed to copy to clipboard: " + err.Error() + AnsiReset)
+2 -4
View File
@@ -11,6 +11,8 @@ import (
"strings"
)
const extendedCharset = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"
// TargetIsFile TargetStatusCheck checks if the targetLocation is a file, directory, or is inaccessible
// failCondition: 0 = fail on inaccessible, 1 = fail on inaccessible/file, 2 = fail on inaccessible/directory
// returns: isFile, isAccessible
@@ -93,17 +95,13 @@ func RemoveTrailingEmptyStrings(slice []string) []string {
// StringGen generates a random string of a specified length and complexity
// complexity: minimum percentage of special characters to be returned in the generated string (only impacts complex strings)
func StringGen(length int, complex bool, complexity float64) string {
var extendedCharset string // hold extended character set used for complex strings
var actualSpecialChars int // track the number of special characters in the generated string
var minSpecialChars int // track the minimum number of special characters to accept
charset := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" // default character set used for all strings
if complex {
minSpecialChars = int(math.Round(float64(length) * complexity)) // determine minimum number of special characters to accept
extendedCharset = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"
charset = charset + extendedCharset
} else {
extendedCharset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
}
// loop until a string of the desired complexity is generated