mirror of
https://github.com/go-delve/delve.git
synced 2025-10-30 02:07:58 +08:00
terminal: do not use escape codes on windows unless they are supported
This commit is contained in:
@ -42,7 +42,7 @@ func New(client service.Client, conf *config.Config) *Term {
|
||||
line: liner.NewLiner(),
|
||||
client: client,
|
||||
cmds: cmds,
|
||||
dumb: strings.ToLower(os.Getenv("TERM")) == "dumb",
|
||||
dumb: !supportsEscapeCodes(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
13
terminal/terminal_other.go
Normal file
13
terminal/terminal_other.go
Normal file
@ -0,0 +1,13 @@
|
||||
// +build !windows
|
||||
|
||||
package terminal
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// supportsEscapeCodes returns true if console handles escape codes.
|
||||
func supportsEscapeCodes() bool {
|
||||
return strings.ToLower(os.Getenv("TERM")) != "dumb"
|
||||
}
|
||||
31
terminal/terminal_windows.go
Normal file
31
terminal/terminal_windows.go
Normal file
@ -0,0 +1,31 @@
|
||||
package terminal
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
// supportsEscapeCodes returns true if console handles escape codes.
|
||||
func supportsEscapeCodes() bool {
|
||||
if strings.ToLower(os.Getenv("TERM")) == "dumb" {
|
||||
return false
|
||||
}
|
||||
if strings.ToLower(os.Getenv("ConEmuANSI")) == "on" {
|
||||
// The ConEmu terminal is installed. Use it.
|
||||
return true
|
||||
}
|
||||
|
||||
const ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x0004
|
||||
|
||||
h, err := syscall.GetStdHandle(syscall.STD_OUTPUT_HANDLE)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
var m uint32
|
||||
err = syscall.GetConsoleMode(h, &m)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return m&ENABLE_VIRTUAL_TERMINAL_PROCESSING != 0
|
||||
}
|
||||
Reference in New Issue
Block a user