mirror of
https://github.com/rwinkhart/libmutton.git
synced 2026-08-28 12:56:31 -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 = "/"
|
||||
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
|
||||
|
||||
import (
|
||||
"os"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
// EntryRoot path to libmutton entry directory
|
||||
var EntryRoot = Home + "\\AppData\\Local\\libmutton\\entries"
|
||||
var ConfigDir = Home + "\\AppData\\Local\\libmutton\\config"
|
||||
@@ -12,3 +17,15 @@ const (
|
||||
PathSeparator = "\\"
|
||||
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 {
|
||||
cmd := exec.Command("gpg", "--pinentry-mode", "loopback", "-q", "-d", targetLocation)
|
||||
output, err := cmd.Output()
|
||||
|
||||
// ensure ANSI escape sequences are interpreted properly on Windows
|
||||
enableVirtualTerminalProcessing()
|
||||
|
||||
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)
|
||||
os.Exit(1)
|
||||
}
|
||||
outputSlice := strings.Split(string(output), "\n")
|
||||
|
||||
return outputSlice
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user