diff --git a/pkg/config/config.go b/pkg/config/config.go index 1ac146c7af..34fd642660 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -57,11 +57,24 @@ type Config struct { // here: https://en.wikipedia.org/wiki/ANSI_escape_code#Colors) SourceListLineColor int `yaml:"source-list-line-color"` + // number of lines to list above and below cursor when printfile() is + // called (i.e. when execution stops, listCommand is used, etc) + SourceListLineCount *int `yaml:"source-list-line-count,omitempty"` + // DebugFileDirectories is the list of directories Delve will use // in order to resolve external debug info files. DebugInfoDirectories []string `yaml:"debug-info-directories"` } +func (c *Config) GetSourceListLineCount() int { + n := 5 // default value + lcp := c.SourceListLineCount + if lcp != nil && *lcp >= 0 { + n = *lcp + } + return n +} + // LoadConfig attempts to populate a Config object from the config.yml file. func LoadConfig() *Config { err := createConfigPath() @@ -204,6 +217,10 @@ func writeDefaultConfig(f *os.File) error { # dark blue) See https://en.wikipedia.org/wiki/ANSI_escape_code#3/4_bit # source-list-line-color: 34 +# Uncomment to change the number of lines printed above and below cursor when +# listing source code. +# source-list-line-count: 5 + # Provided aliases will be added to the default aliases for a given command. aliases: # command: ["alias1", "alias2"] diff --git a/pkg/terminal/command.go b/pkg/terminal/command.go index 5e9c2e7fed..94f284592c 100644 --- a/pkg/terminal/command.go +++ b/pkg/terminal/command.go @@ -2227,20 +2227,22 @@ func printfile(t *Term, filename string, line int, showArrow bool) error { fmt.Println("Warning: listing may not match stale executable") } + lineCount := t.conf.GetSourceListLineCount() + buf := bufio.NewScanner(file) l := line - for i := 1; i < l-5; i++ { + for i := 1; i < l-lineCount; i++ { if !buf.Scan() { return nil } } - s := l - 5 + s := l - lineCount if s < 1 { s = 1 } - for i := s; i <= l+5; i++ { + for i := s; i <= l+lineCount; i++ { if !buf.Scan() { return nil }