提交 76b9aa03 编写于 作者: F Florin Patan 提交者: Derek Parker

terminal/command: Support for dumb terminal

Support for dumb terminal

Fixes #252
上级 af16cfa9
...@@ -47,6 +47,8 @@ type Commands struct { ...@@ -47,6 +47,8 @@ type Commands struct {
client service.Client client service.Client
} }
var dumbTerminal = strings.ToLower(os.Getenv("TERM")) == "dumb"
// Returns a Commands struct with default commands defined. // Returns a Commands struct with default commands defined.
func DebugCommands(client service.Client) *Commands { func DebugCommands(client service.Client) *Commands {
c := &Commands{client: client} c := &Commands{client: client}
...@@ -733,7 +735,11 @@ func printcontext(state *api.DebuggerState) error { ...@@ -733,7 +735,11 @@ func printcontext(state *api.DebuggerState) error {
} }
if len(state.CurrentThread.File) == 0 { if len(state.CurrentThread.File) == 0 {
fmt.Printf("Stopped at: 0x%x\n", state.CurrentThread.PC) fmt.Printf("Stopped at: 0x%x\n", state.CurrentThread.PC)
fmt.Printf("\033[34m=>\033[0m no source available\n") if dumbTerminal {
fmt.Printf("=> no source available\n")
} else {
fmt.Printf("\033[34m=>\033[0m no source available\n")
}
return nil return nil
} }
var fn *api.Function var fn *api.Function
...@@ -817,10 +823,18 @@ func printfile(filename string, line int, showArrow bool) error { ...@@ -817,10 +823,18 @@ func printfile(filename string, line int, showArrow bool) error {
} }
var lineNum string var lineNum string
if i < 10 { if dumbTerminal {
lineNum = fmt.Sprintf("\033[34m%s %d\033[0m:\t", arrow, i) if i < 10 {
lineNum = fmt.Sprintf("%s %d:\t", arrow, i)
} else {
lineNum = fmt.Sprintf("%s %d:\t", arrow, i)
}
} else { } else {
lineNum = fmt.Sprintf("\033[34m%s %d\033[0m:\t", arrow, i) if i < 10 {
lineNum = fmt.Sprintf("\033[34m%s %d\033[0m:\t", arrow, i)
} else {
lineNum = fmt.Sprintf("\033[34m%s %d\033[0m:\t", arrow, i)
}
} }
context = append(context, lineNum+line) context = append(context, lineNum+line)
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册