diff --git a/pkg/config/split.go b/pkg/config/split.go index a60b07d3f1..94a216be15 100644 --- a/pkg/config/split.go +++ b/pkg/config/split.go @@ -84,7 +84,28 @@ func ConfigureSetSimple(rest string, cfgname string, field reflect.Value) error v := rest == "true" return reflect.ValueOf(&v), nil case reflect.String: + unquoted, err := strconv.Unquote(rest) + if err == nil { + rest = unquoted + } return reflect.ValueOf(&rest), nil + case reflect.Interface: + // We special case this particular configuration key because historically we accept both a numerical value and a string value for it. + if cfgname == "source-list-line-color" { + n, err := strconv.Atoi(rest) + if err == nil { + if n < 0 { + return reflect.ValueOf(nil), fmt.Errorf("argument to %q must be a number greater than zero", cfgname) + } + return reflect.ValueOf(&n), nil + } + unquoted, err := strconv.Unquote(rest) + if err == nil { + rest = unquoted + } + return reflect.ValueOf(&rest), nil + } + fallthrough default: return reflect.ValueOf(nil), fmt.Errorf("unsupported type for configuration key %q", cfgname) } diff --git a/pkg/terminal/config.go b/pkg/terminal/config.go index a005c51aa6..9d7f43d287 100644 --- a/pkg/terminal/config.go +++ b/pkg/terminal/config.go @@ -25,6 +25,7 @@ func configureCmd(t *Term, ctx callContext, args string) error { if t.client != nil { // only happens in tests lcfg := t.loadConfig() t.client.SetReturnValuesLoadConfig(&lcfg) + t.updateColorScheme() } return nil } diff --git a/pkg/terminal/terminal.go b/pkg/terminal/terminal.go index e04b77add5..b4cde64c58 100644 --- a/pkg/terminal/terminal.go +++ b/pkg/terminal/terminal.go @@ -108,28 +108,7 @@ func New(client service.Client, conf *config.Config) *Term { t.stdout.pw = &pagingWriter{w: getColorableWriter()} t.stdout.colorEscapes = make(map[colorize.Style]string) t.stdout.colorEscapes[colorize.NormalStyle] = terminalResetEscapeCode - wd := func(s string, defaultCode int) string { - if s == "" { - return fmt.Sprintf(terminalHighlightEscapeCode, defaultCode) - } - return s - } - t.stdout.colorEscapes[colorize.KeywordStyle] = conf.SourceListKeywordColor - t.stdout.colorEscapes[colorize.StringStyle] = wd(conf.SourceListStringColor, ansiGreen) - t.stdout.colorEscapes[colorize.NumberStyle] = conf.SourceListNumberColor - t.stdout.colorEscapes[colorize.CommentStyle] = wd(conf.SourceListCommentColor, ansiBrMagenta) - t.stdout.colorEscapes[colorize.ArrowStyle] = wd(conf.SourceListArrowColor, ansiYellow) - switch x := conf.SourceListLineColor.(type) { - case string: - t.stdout.colorEscapes[colorize.LineNoStyle] = x - case int: - if (x > ansiWhite && x < ansiBrBlack) || x < ansiBlack || x > ansiBrWhite { - x = ansiBlue - } - t.stdout.colorEscapes[colorize.LineNoStyle] = fmt.Sprintf(terminalHighlightEscapeCode, x) - case nil: - t.stdout.colorEscapes[colorize.LineNoStyle] = fmt.Sprintf(terminalHighlightEscapeCode, ansiBlue) - } + t.updateColorScheme() } if client != nil { @@ -141,6 +120,36 @@ func New(client service.Client, conf *config.Config) *Term { return t } +func (t *Term) updateColorScheme() { + if t.stdout.colorEscapes == nil { + return + } + + conf := t.conf + wd := func(s string, defaultCode int) string { + if s == "" { + return fmt.Sprintf(terminalHighlightEscapeCode, defaultCode) + } + return s + } + t.stdout.colorEscapes[colorize.KeywordStyle] = conf.SourceListKeywordColor + t.stdout.colorEscapes[colorize.StringStyle] = wd(conf.SourceListStringColor, ansiGreen) + t.stdout.colorEscapes[colorize.NumberStyle] = conf.SourceListNumberColor + t.stdout.colorEscapes[colorize.CommentStyle] = wd(conf.SourceListCommentColor, ansiBrMagenta) + t.stdout.colorEscapes[colorize.ArrowStyle] = wd(conf.SourceListArrowColor, ansiYellow) + switch x := conf.SourceListLineColor.(type) { + case string: + t.stdout.colorEscapes[colorize.LineNoStyle] = x + case int: + if (x > ansiWhite && x < ansiBrBlack) || x < ansiBlack || x > ansiBrWhite { + x = ansiBlue + } + t.stdout.colorEscapes[colorize.LineNoStyle] = fmt.Sprintf(terminalHighlightEscapeCode, x) + case nil: + t.stdout.colorEscapes[colorize.LineNoStyle] = fmt.Sprintf(terminalHighlightEscapeCode, ansiBlue) + } +} + func (t *Term) SetTraceNonInteractive() { t.traceNonInteractive = true }