From 76b9aa03bb61765735a78c71b5682698653fd5b7 Mon Sep 17 00:00:00 2001 From: Florin Patan Date: Fri, 25 Sep 2015 22:18:53 +0200 Subject: [PATCH] terminal/command: Support for dumb terminal Support for dumb terminal Fixes #252 --- terminal/command.go | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/terminal/command.go b/terminal/command.go index 6860c7c7..fca42956 100644 --- a/terminal/command.go +++ b/terminal/command.go @@ -47,6 +47,8 @@ type Commands struct { client service.Client } +var dumbTerminal = strings.ToLower(os.Getenv("TERM")) == "dumb" + // Returns a Commands struct with default commands defined. func DebugCommands(client service.Client) *Commands { c := &Commands{client: client} @@ -733,7 +735,11 @@ func printcontext(state *api.DebuggerState) error { } if len(state.CurrentThread.File) == 0 { 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 } var fn *api.Function @@ -817,10 +823,18 @@ func printfile(filename string, line int, showArrow bool) error { } var lineNum string - if i < 10 { - lineNum = fmt.Sprintf("\033[34m%s %d\033[0m:\t", arrow, i) + if dumbTerminal { + if i < 10 { + lineNum = fmt.Sprintf("%s %d:\t", arrow, i) + } else { + lineNum = fmt.Sprintf("%s %d:\t", arrow, i) + } } 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) } -- GitLab