terminal/command: Support for dumb terminal

Support for dumb terminal

Fixes #252
This commit is contained in:
Florin Patan 2015-09-25 22:18:53 +02:00 committed by Derek Parker
parent af16cfa90b
commit 76b9aa03bb

@ -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 {
} }
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)
if dumbTerminal {
fmt.Printf("=> no source available\n")
} else {
fmt.Printf("\033[34m=>\033[0m no source available\n") fmt.Printf("\033[34m=>\033[0m no source available\n")
}
return nil return nil
} }
var fn *api.Function var fn *api.Function
@ -817,11 +823,19 @@ func printfile(filename string, line int, showArrow bool) error {
} }
var lineNum string var lineNum string
if dumbTerminal {
if i < 10 {
lineNum = fmt.Sprintf("%s %d:\t", arrow, i)
} else {
lineNum = fmt.Sprintf("%s %d:\t", arrow, i)
}
} else {
if i < 10 { if i < 10 {
lineNum = fmt.Sprintf("\033[34m%s %d\033[0m:\t", arrow, i) lineNum = fmt.Sprintf("\033[34m%s %d\033[0m:\t", arrow, i)
} else { } else {
lineNum = fmt.Sprintf("\033[34m%s %d\033[0m:\t", arrow, i) lineNum = fmt.Sprintf("\033[34m%s %d\033[0m:\t", arrow, i)
} }
}
context = append(context, lineNum+line) context = append(context, lineNum+line)
} }