pkg/terminal: fix handling list colors via config (#3240)
Parsing the source list color when set during a Delve debug session resulted in unexpected errors. Additionally the changes were not reflected in the current session, forcing the user to save the config and start a new session. This patch fixes those issues.
This commit is contained in:
parent
709da9a217
commit
9230a97210
@ -84,7 +84,28 @@ func ConfigureSetSimple(rest string, cfgname string, field reflect.Value) error
|
|||||||
v := rest == "true"
|
v := rest == "true"
|
||||||
return reflect.ValueOf(&v), nil
|
return reflect.ValueOf(&v), nil
|
||||||
case reflect.String:
|
case reflect.String:
|
||||||
|
unquoted, err := strconv.Unquote(rest)
|
||||||
|
if err == nil {
|
||||||
|
rest = unquoted
|
||||||
|
}
|
||||||
return reflect.ValueOf(&rest), nil
|
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:
|
default:
|
||||||
return reflect.ValueOf(nil), fmt.Errorf("unsupported type for configuration key %q", cfgname)
|
return reflect.ValueOf(nil), fmt.Errorf("unsupported type for configuration key %q", cfgname)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,6 +25,7 @@ func configureCmd(t *Term, ctx callContext, args string) error {
|
|||||||
if t.client != nil { // only happens in tests
|
if t.client != nil { // only happens in tests
|
||||||
lcfg := t.loadConfig()
|
lcfg := t.loadConfig()
|
||||||
t.client.SetReturnValuesLoadConfig(&lcfg)
|
t.client.SetReturnValuesLoadConfig(&lcfg)
|
||||||
|
t.updateColorScheme()
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@ -108,6 +108,24 @@ func New(client service.Client, conf *config.Config) *Term {
|
|||||||
t.stdout.pw = &pagingWriter{w: getColorableWriter()}
|
t.stdout.pw = &pagingWriter{w: getColorableWriter()}
|
||||||
t.stdout.colorEscapes = make(map[colorize.Style]string)
|
t.stdout.colorEscapes = make(map[colorize.Style]string)
|
||||||
t.stdout.colorEscapes[colorize.NormalStyle] = terminalResetEscapeCode
|
t.stdout.colorEscapes[colorize.NormalStyle] = terminalResetEscapeCode
|
||||||
|
t.updateColorScheme()
|
||||||
|
}
|
||||||
|
|
||||||
|
if client != nil {
|
||||||
|
lcfg := t.loadConfig()
|
||||||
|
client.SetReturnValuesLoadConfig(&lcfg)
|
||||||
|
}
|
||||||
|
|
||||||
|
t.starlarkEnv = starbind.New(starlarkContext{t}, t.stdout)
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *Term) updateColorScheme() {
|
||||||
|
if t.stdout.colorEscapes == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
conf := t.conf
|
||||||
wd := func(s string, defaultCode int) string {
|
wd := func(s string, defaultCode int) string {
|
||||||
if s == "" {
|
if s == "" {
|
||||||
return fmt.Sprintf(terminalHighlightEscapeCode, defaultCode)
|
return fmt.Sprintf(terminalHighlightEscapeCode, defaultCode)
|
||||||
@ -130,15 +148,6 @@ func New(client service.Client, conf *config.Config) *Term {
|
|||||||
case nil:
|
case nil:
|
||||||
t.stdout.colorEscapes[colorize.LineNoStyle] = fmt.Sprintf(terminalHighlightEscapeCode, ansiBlue)
|
t.stdout.colorEscapes[colorize.LineNoStyle] = fmt.Sprintf(terminalHighlightEscapeCode, ansiBlue)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if client != nil {
|
|
||||||
lcfg := t.loadConfig()
|
|
||||||
client.SetReturnValuesLoadConfig(&lcfg)
|
|
||||||
}
|
|
||||||
|
|
||||||
t.starlarkEnv = starbind.New(starlarkContext{t}, t.stdout)
|
|
||||||
return t
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Term) SetTraceNonInteractive() {
|
func (t *Term) SetTraceNonInteractive() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user