-
Notifications
You must be signed in to change notification settings - Fork 0
/
winhelper.go
47 lines (42 loc) · 944 Bytes
/
winhelper.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// +build windows
package gohelper
import (
"fmt"
"os"
"os/exec"
"golang.org/x/sys/windows/registry"
)
// Cwindows ...Edit registry to suppory ANSII
func Cwindows() error {
reg, err := registry.OpenKey(registry.CURRENT_USER, `Console`, registry.QUERY_VALUE)
if err != nil {
return err
}
s, _, err := reg.GetIntegerValue("VirtualTerminalLevel")
reg.Close()
if s == 0 {
reg, err = registry.OpenKey(registry.CURRENT_USER, `Console`, registry.WRITE)
if err != nil {
return err
}
err = reg.SetDWordValue("VirtualTerminalLevel", 0x00000001)
if err != nil {
return err
}
err = reg.SetDWordValue("VirtualTerminalLevel", 0x00000000)
if err != nil {
return err
}
reg.Close()
cmd := exec.Command("cmd")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
return err
}
fmt.Printf("\033[2J\033[H")
// if err := undo(); err != nil {
// return err
}
return nil
}