config,terminal: Add source-list-line-color configuration option
This change adds a config flag to specify the foreground color of line numbers for the source list command.
This commit is contained in:
parent
ea54a6b2af
commit
4e4ed02948
@ -43,6 +43,10 @@ type Config struct {
|
||||
// If ShowLocationExpr is true whatis will print the DWARF location
|
||||
// expression for its argument.
|
||||
ShowLocationExpr bool `yaml:"show-location-expr"`
|
||||
|
||||
// Source list line-number color (3/4 bit color codes as defined
|
||||
// here: https://en.wikipedia.org/wiki/ANSI_escape_code#Colors)
|
||||
SourceListLineColor int `yaml:"source-list-line-color"`
|
||||
}
|
||||
|
||||
// LoadConfig attempts to populate a Config object from the config.yml file.
|
||||
@ -129,6 +133,11 @@ func writeDefaultConfig(f *os.File) error {
|
||||
# This is the default configuration file. Available options are provided, but disabled.
|
||||
# Delete the leading hash mark to enable an item.
|
||||
|
||||
# Uncomment the following line and set your preferred ANSI foreground color
|
||||
# for source line numbers in the (list) command (if unset, default is 34,
|
||||
# dark blue) See https://en.wikipedia.org/wiki/ANSI_escape_code#3/4_bit
|
||||
# source-list-line-color: 34
|
||||
|
||||
# Provided aliases will be added to the default aliases for a given command.
|
||||
aliases:
|
||||
# command: ["alias1", "alias2"]
|
||||
|
||||
@ -19,9 +19,28 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
historyFile string = ".dbg_history"
|
||||
terminalBlueEscapeCode string = "\033[34m"
|
||||
terminalResetEscapeCode string = "\033[0m"
|
||||
historyFile string = ".dbg_history"
|
||||
terminalHighlightEscapeCode string = "\033[%2dm"
|
||||
terminalResetEscapeCode string = "\033[0m"
|
||||
)
|
||||
|
||||
const (
|
||||
ansiBlack = 30
|
||||
ansiRed = 31
|
||||
ansiGreen = 32
|
||||
ansiYellow = 33
|
||||
ansiBlue = 34
|
||||
ansiMagenta = 35
|
||||
ansiCyan = 36
|
||||
ansiWhite = 37
|
||||
ansiBrBlack = 90
|
||||
ansiBrRed = 91
|
||||
ansiBrGreen = 92
|
||||
ansiBrYellow = 93
|
||||
ansiBrBlue = 94
|
||||
ansiBrMagenta = 95
|
||||
ansiBrCyan = 96
|
||||
ansiBrWhite = 97
|
||||
)
|
||||
|
||||
// Term represents the terminal running dlv.
|
||||
@ -81,6 +100,13 @@ func New(client service.Client, conf *config.Config) *Term {
|
||||
client.SetReturnValuesLoadConfig(&LongLoadConfig)
|
||||
}
|
||||
|
||||
if (conf.SourceListLineColor > ansiWhite &&
|
||||
conf.SourceListLineColor < ansiBrBlack) ||
|
||||
conf.SourceListLineColor < ansiBlack ||
|
||||
conf.SourceListLineColor > ansiBrWhite {
|
||||
conf.SourceListLineColor = ansiBlue
|
||||
}
|
||||
|
||||
return &Term{
|
||||
client: client,
|
||||
conf: conf,
|
||||
@ -217,7 +243,8 @@ func (t *Term) Run() (int, error) {
|
||||
// Println prints a line to the terminal.
|
||||
func (t *Term) Println(prefix, str string) {
|
||||
if !t.dumb {
|
||||
prefix = fmt.Sprintf("%s%s%s", terminalBlueEscapeCode, prefix, terminalResetEscapeCode)
|
||||
terminalColorEscapeCode := fmt.Sprintf(terminalHighlightEscapeCode, t.conf.SourceListLineColor)
|
||||
prefix = fmt.Sprintf("%s%s%s", terminalColorEscapeCode, prefix, terminalResetEscapeCode)
|
||||
}
|
||||
fmt.Fprintf(t.stdout, "%s%s\n", prefix, str)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user