mirror of
https://github.com/go-delve/delve.git
synced 2025-11-03 05:47:34 +08:00
terminal: Use go-colorable
Add fallback to display colors on Windows.
This commit is contained in:
committed by
Derek Parker
parent
af4798e2a9
commit
f6836cbcf1
@ -1,31 +1,35 @@
|
||||
package terminal
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"github.com/mattn/go-colorable"
|
||||
)
|
||||
|
||||
// supportsEscapeCodes returns true if console handles escape codes.
|
||||
func supportsEscapeCodes() bool {
|
||||
if strings.ToLower(os.Getenv("TERM")) == "dumb" {
|
||||
return false
|
||||
}
|
||||
// getColorableWriter returns two values. First is Writer supported colors.
|
||||
// If return nil, colors will be disabled.
|
||||
func getColorableWriter() io.Writer {
|
||||
if strings.ToLower(os.Getenv("ConEmuANSI")) == "on" {
|
||||
// The ConEmu terminal is installed. Use it.
|
||||
return true
|
||||
return os.Stdout
|
||||
}
|
||||
|
||||
const ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x0004
|
||||
|
||||
h, err := syscall.GetStdHandle(syscall.STD_OUTPUT_HANDLE)
|
||||
if err != nil {
|
||||
return false
|
||||
return os.Stdout
|
||||
}
|
||||
var m uint32
|
||||
err = syscall.GetConsoleMode(h, &m)
|
||||
if err != nil {
|
||||
return false
|
||||
return os.Stdout
|
||||
}
|
||||
return m&ENABLE_VIRTUAL_TERMINAL_PROCESSING != 0
|
||||
if m&ENABLE_VIRTUAL_TERMINAL_PROCESSING != 0 {
|
||||
return os.Stdout
|
||||
}
|
||||
return colorable.NewColorableStdout()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user