mirror of
https://github.com/rwinkhart/libmutton.git
synced 2026-09-01 06:46:38 -04:00
Fix ANSI escapes (on Windows) not being interpreted after using GPG pinentry
This commit is contained in:
@@ -12,3 +12,9 @@ const (
|
|||||||
PathSeparator = "/"
|
PathSeparator = "/"
|
||||||
IsWindows = false
|
IsWindows = false
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// enableVirtualTerminalProcessing is a dummy function on UNIX-like systems (only needed on Windows)
|
||||||
|
// TODO remove after migration off of GPG, as pinentry is responsible for disabling ANSI escape sequence interpretation
|
||||||
|
func enableVirtualTerminalProcessing() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,11 @@
|
|||||||
|
|
||||||
package backend
|
package backend
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"syscall"
|
||||||
|
)
|
||||||
|
|
||||||
// EntryRoot path to libmutton entry directory
|
// EntryRoot path to libmutton entry directory
|
||||||
var EntryRoot = Home + "\\AppData\\Local\\libmutton\\entries"
|
var EntryRoot = Home + "\\AppData\\Local\\libmutton\\entries"
|
||||||
var ConfigDir = Home + "\\AppData\\Local\\libmutton\\config"
|
var ConfigDir = Home + "\\AppData\\Local\\libmutton\\config"
|
||||||
@@ -12,3 +17,15 @@ const (
|
|||||||
PathSeparator = "\\"
|
PathSeparator = "\\"
|
||||||
IsWindows = true
|
IsWindows = true
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// enableVirtualTerminalProcessing ensures ANSI escape sequences are interpreted properly on Windows
|
||||||
|
// TODO remove after migration off of GPG, as pinentry is responsible for disabling ANSI escape sequence interpretation
|
||||||
|
func enableVirtualTerminalProcessing() {
|
||||||
|
stdout := syscall.Handle(os.Stdout.Fd())
|
||||||
|
|
||||||
|
var originalMode uint32
|
||||||
|
syscall.GetConsoleMode(stdout, &originalMode)
|
||||||
|
originalMode |= 0x0004
|
||||||
|
|
||||||
|
syscall.MustLoadDLL("kernel32").MustFindProc("SetConsoleMode").Call(uintptr(stdout), uintptr(originalMode))
|
||||||
|
}
|
||||||
|
|||||||
@@ -13,11 +13,16 @@ import (
|
|||||||
func DecryptGPG(targetLocation string) []string {
|
func DecryptGPG(targetLocation string) []string {
|
||||||
cmd := exec.Command("gpg", "--pinentry-mode", "loopback", "-q", "-d", targetLocation)
|
cmd := exec.Command("gpg", "--pinentry-mode", "loopback", "-q", "-d", targetLocation)
|
||||||
output, err := cmd.Output()
|
output, err := cmd.Output()
|
||||||
|
|
||||||
|
// ensure ANSI escape sequences are interpreted properly on Windows
|
||||||
|
enableVirtualTerminalProcessing()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(AnsiError + "Failed to decrypt \"" + targetLocation + "\" - ensure it is a valid GPG-encrypted file and that you entered your passphrase correctly" + AnsiReset)
|
fmt.Println(AnsiError + "Failed to decrypt \"" + targetLocation + "\" - ensure it is a valid GPG-encrypted file and that you entered your passphrase correctly" + AnsiReset)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
outputSlice := strings.Split(string(output), "\n")
|
outputSlice := strings.Split(string(output), "\n")
|
||||||
|
|
||||||
return outputSlice
|
return outputSlice
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
# Known Bugs - libmutton
|
||||||
|
- On Windows, GPG is sometimes (seems unpredictable) incredibly slow to start (often after a reboot), leading to many operations seemingly hanging
|
||||||
|
- **This will be addressed** in the migration off of GPG that will take place before v1.0.0
|
||||||
Reference in New Issue
Block a user