Created
October 13, 2017 12:07
-
-
Save Ankur008/e5a740ac33948744877b1b6594714670 to your computer and use it in GitHub Desktop.
Func to print the line no, code and current local variable with value
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func printCode(t *Term, filename string, line int, showArrow bool,th *api.Thread,ctx callContext,args string) error { | |
file, err := os.Open(t.substitutePath(filename)) | |
if err != nil { | |
return err | |
} | |
defer file.Close() | |
fi, _ := file.Stat() | |
lastModExe := t.client.LastModified() | |
if fi.ModTime().After(lastModExe) { | |
fmt.Println("Warning: listing may not match stale executable") | |
} | |
buf := bufio.NewScanner(file) | |
l := line | |
for i := 1; i < l-5; i++ { | |
if !buf.Scan() { | |
return nil | |
} | |
} | |
s := l - 5 | |
if s < 1 { | |
s = 1 | |
} | |
for i := s; i <= l+5; i++ { | |
if !buf.Scan() { | |
return nil | |
} | |
var prefix string | |
if showArrow { | |
prefix = " " | |
if i == l { | |
prefix = "=>" | |
} | |
} | |
prefix = fmt.Sprintf("%s%4d:\t", prefix, i) | |
//t.Println(prefix, buf.Text()) | |
//print the code | |
fmt.Printf("> (%s) %s:%d\n", | |
buf.Text(), | |
th.File, | |
th.Line) | |
locals(t,ctx,args) | |
fmt.Println() | |
} | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment