github.com/neilgarb/delve@v1.9.2-nobreaks/pkg/terminal/terminal_windows.go (about)

     1  package terminal
     2  
     3  import (
     4  	"io"
     5  	"os"
     6  	"strings"
     7  	"syscall"
     8  
     9  	"github.com/mattn/go-colorable"
    10  )
    11  
    12  // getColorableWriter will return a writer that is capable
    13  // of interpreting ANSI escape codes for terminal colors.
    14  func getColorableWriter() io.Writer {
    15  	if strings.ToLower(os.Getenv("ConEmuANSI")) == "on" {
    16  		// The ConEmu terminal is installed. Use it.
    17  		return os.Stdout
    18  	}
    19  
    20  	const ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x0004
    21  
    22  	h, err := syscall.GetStdHandle(syscall.STD_OUTPUT_HANDLE)
    23  	if err != nil {
    24  		return os.Stdout
    25  	}
    26  	var m uint32
    27  	err = syscall.GetConsoleMode(h, &m)
    28  	if err != nil {
    29  		return os.Stdout
    30  	}
    31  	if m&ENABLE_VIRTUAL_TERMINAL_PROCESSING != 0 {
    32  		return os.Stdout
    33  	}
    34  	return colorable.NewColorableStdout()
    35  }