11 type myWriter struct {
15 func (w *myWriter) Write(p []byte) (int, error) {
16 return 0, fmt.Errorf("not implemented")
19 func (w *myWriter) Fd() uintptr {
23 var procGetStdHandle = kernel32.NewProc("GetStdHandle")
25 const stdOutputHandle = ^uintptr(0) - 11 + 1
27 func getConsoleHandle() syscall.Handle {
28 ptr, err := syscall.UTF16PtrFromString("CONOUT$")
34 handle, err := syscall.CreateFile(ptr, syscall.GENERIC_READ|syscall.GENERIC_WRITE, syscall.FILE_SHARE_READ, nil, syscall.OPEN_EXISTING, 0, 0)
43 func TestIsTerminal(t *testing.T) {
44 // This is necessary because depending on whether `go test` is called with
45 // the `-v` option, stdout will or will not be bound, changing the behavior
46 // of the test. So we refer to it directly to avoid flakyness.
47 handle := getConsoleHandle()
53 if !IsTerminal(writer) {
54 t.Errorf("output is supposed to be a terminal")
58 func TestIsConsole(t *testing.T) {
59 // This is necessary because depending on whether `go test` is called with
60 // the `-v` option, stdout will or will not be bound, changing the behavior
61 // of the test. So we refer to it directly to avoid flakyness.
62 handle := getConsoleHandle()
68 if !IsConsole(writer) {
69 t.Errorf("output is supposed to be a console")