Skip to content

Instantly share code, notes, and snippets.

@shiena
Last active August 29, 2015 14:00
Show Gist options
  • Save shiena/11408280 to your computer and use it in GitHub Desktop.
Save shiena/11408280 to your computer and use it in GitHub Desktop.
ansi color
// For details, please refer to the following URL.
// http://golangtc.com/member/foxhack
// http://www.mailsend-online.com/blog/setting-windows-console-text-colors-in-c.html
package main
import (
"fmt"
"syscall"
)
func ColorPrint(s string, i int) {
kernel32 := syscall.NewLazyDLL("kernel32.dll")
proc := kernel32.NewProc("SetConsoleTextAttribute")
handle, _, _ := proc.Call(uintptr(syscall.Stdout), uintptr(i))
fmt.Print(s)
handle, _, _ = proc.Call(uintptr(syscall.Stdout), uintptr(7))
CloseHandle := kernel32.NewProc("CloseHandle")
CloseHandle.Call(handle)
}
func main() {
for i := 0; i < 16; i++ {
for j := 0; j < 16; j++ {
ColorPrint(fmt.Sprintf("%02d,%02d ", i, j), i*16+j)
}
fmt.Println()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment