This repository was archived by the owner on Aug 3, 2022. It is now read-only.
File tree 1 file changed +41
-0
lines changed
1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change 15
15
16
16
package info
17
17
18
+ import (
19
+ "fmt"
20
+ "os"
21
+
22
+ "golang.org/x/sys/windows"
23
+ )
24
+
18
25
// Information about the current system
19
26
const (
20
27
OsName = "Windows"
21
28
OsDir = "windows"
22
29
)
30
+
31
+ // Windows by default ignores ASCII escape codes,
32
+ // however we can change this using this.
33
+ // Why is this not the default? No idea...
34
+ func init () {
35
+ // Get a handle to the console
36
+ stdOutHandle , err := windows .GetStdHandle (windows .STD_OUTPUT_HANDLE )
37
+
38
+ if err != nil {
39
+ fmt .Println ("Failed to get a handle for standard input, please open an issue, this should work..." )
40
+ fmt .Println (err )
41
+ os .Exit (1 )
42
+ }
43
+
44
+ // Get the current console settings
45
+ var consoleMode uint32 = 0
46
+ err = windows .GetConsoleMode (stdOutHandle , & consoleMode )
47
+
48
+ if err != nil {
49
+ fmt .Println ("Failed to get current terminal mode, please open an issue, this should work..." )
50
+ fmt .Println (err )
51
+ os .Exit (1 )
52
+ }
53
+
54
+ // Add support for escape codes to those settings
55
+ consoleMode |= windows .ENABLE_VIRTUAL_TERMINAL_PROCESSING
56
+ err = windows .SetConsoleMode (stdOutHandle , consoleMode )
57
+
58
+ if err != nil {
59
+ fmt .Println ("Failed to enable ASCII escape sequences, please open an issue, this should work..." )
60
+ fmt .Println (err )
61
+ os .Exit (1 )
62
+ }
63
+ }
You can’t perform that action at this time.
0 commit comments