~poldi1405/go-ansi

ref: 76d320c6afe7577b81dc9a9196484bbcad5057a9 go-ansi/preparation_windows.go -rw-r--r-- 718 bytes
76d320c6 — Moritz Poldrack added function to remove all ANSI-Codes from a string 1 year, 5 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package ansi

import (
	"os"
	"syscall"
)

// EnableANSI allows windows terminals to also enjoy the beauty of formatted
// output. This is not in the init function to prevent messing with the users
// environment. On other OSes this function does absolutely nothing but does
// still exist to allow easy cross-platform development. If you are on any OS
// other than Windows and your Terminal does not support ANSI Sequences I'd
// reccomend you get a normal terminal emulator.
func EnableANSI() {
	handle := syscall.Handle(os.Stdout.Fd())
	kernel32DLL := syscall.NewLazyDLL("kernel32.dll")
	setConsoleModeProc := kernel32DLL.NewProc("SetConsoleMode")
	setConsoleModeProc.Call(uintptr(handle), 0x0001|0x0002|0x0004)
}