config: add option for printfile() line count (#2043)
The option is "source-list-line-count". It defaults to 5, which was previously hardcoded in printfile(), but now you can change it dynamically, for instance: $ config source-list-line-count 20 $ list
This commit is contained in:
parent
f559c3c421
commit
71a460fc0f
@ -57,11 +57,24 @@ type Config struct {
|
|||||||
// here: https://en.wikipedia.org/wiki/ANSI_escape_code#Colors)
|
// here: https://en.wikipedia.org/wiki/ANSI_escape_code#Colors)
|
||||||
SourceListLineColor int `yaml:"source-list-line-color"`
|
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
|
// DebugFileDirectories is the list of directories Delve will use
|
||||||
// in order to resolve external debug info files.
|
// in order to resolve external debug info files.
|
||||||
DebugInfoDirectories []string `yaml:"debug-info-directories"`
|
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.
|
// LoadConfig attempts to populate a Config object from the config.yml file.
|
||||||
func LoadConfig() *Config {
|
func LoadConfig() *Config {
|
||||||
err := createConfigPath()
|
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
|
# dark blue) See https://en.wikipedia.org/wiki/ANSI_escape_code#3/4_bit
|
||||||
# source-list-line-color: 34
|
# 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.
|
# Provided aliases will be added to the default aliases for a given command.
|
||||||
aliases:
|
aliases:
|
||||||
# command: ["alias1", "alias2"]
|
# command: ["alias1", "alias2"]
|
||||||
|
|||||||
@ -2227,20 +2227,22 @@ func printfile(t *Term, filename string, line int, showArrow bool) error {
|
|||||||
fmt.Println("Warning: listing may not match stale executable")
|
fmt.Println("Warning: listing may not match stale executable")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lineCount := t.conf.GetSourceListLineCount()
|
||||||
|
|
||||||
buf := bufio.NewScanner(file)
|
buf := bufio.NewScanner(file)
|
||||||
l := line
|
l := line
|
||||||
for i := 1; i < l-5; i++ {
|
for i := 1; i < l-lineCount; i++ {
|
||||||
if !buf.Scan() {
|
if !buf.Scan() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
s := l - 5
|
s := l - lineCount
|
||||||
if s < 1 {
|
if s < 1 {
|
||||||
s = 1
|
s = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := s; i <= l+5; i++ {
|
for i := s; i <= l+lineCount; i++ {
|
||||||
if !buf.Scan() {
|
if !buf.Scan() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user