From 4e4ed0294807c7be65513112bde18dd70c0f165f Mon Sep 17 00:00:00 2001 From: Russ Magee Date: Wed, 10 Oct 2018 09:42:32 -0700 Subject: [PATCH] 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. --- pkg/config/config.go | 9 +++++++++ pkg/terminal/terminal.go | 35 +++++++++++++++++++++++++++++++---- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index 5cc6dad4..297abac3 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -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"] diff --git a/pkg/terminal/terminal.go b/pkg/terminal/terminal.go index a7af7e2d..a9808377 100644 --- a/pkg/terminal/terminal.go +++ b/pkg/terminal/terminal.go @@ -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) } -- GitLab