From 10dbc4bedac6e5fbf2a90314b3914e849598da1b Mon Sep 17 00:00:00 2001 From: Derek Parker Date: Fri, 17 Oct 2014 14:33:40 -0500 Subject: [PATCH] Add line numbers to context output --- command/command.go | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/command/command.go b/command/command.go index 8653d544..8ca7122c 100644 --- a/command/command.go +++ b/command/command.go @@ -216,21 +216,34 @@ func printcontext(p *proctl.DebuggedProcess) error { defer file.Close() buf := bufio.NewReader(file) - for i := 1; i <= l+5; i++ { - line, err := buf.ReadString('\n') + for i := 1; i < l-5; i++ { + _, err := buf.ReadString('\n') if err != nil && err != io.EOF { return err } - - if i >= (l - 5) { - if i == l { - line = "=>" + line - } - context = append(context, line) - } } - fmt.Println(strings.Join(context, " ")) + for i := l - 5; i <= l+5; i++ { + line, err := buf.ReadString('\n') + if err != nil { + if err != io.EOF { + return err + } + + if err == io.EOF { + break + } + } + + if i == l { + line = "=>" + line + } + + line = strconv.Itoa(i) + ": " + line + context = append(context, line) + } + + fmt.Println(strings.Join(context, "")) return nil }