Skip to content
Myr

Fix #370 - Panic when trying to set colors when colors are disabled

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Junegunn Choi · committed by Junegunn Choi · parent 1da065e · Browse files · 2 files+18 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+18 added−3 removed

  • other:+18 added−3 removed

2 files+18 added−3 removed

modified:src/options_test.go+12 added
314 unmodified lines
315 if !curses.Dark256.UseDefault {316 t.Errorf("using default colors")317 }318}319320func TestParseNilTheme(t *testing.T) {321 var theme *curses.ColorTheme322 newTheme := parseTheme(theme, "prompt:12")323 if newTheme != nil {324 t.Errorf("color is disabled. keep it that way.")325 }326 newTheme = parseTheme(theme, "prompt:12,dark,prompt:13")327 if newTheme.Prompt != 13 {328 t.Errorf("color should now be enabled and customized")329 }330}
modified:src/options.go+6 added-3 removed
378 unmodified lines
379 return byLength380}381382func dupeTheme(theme *curses.ColorTheme) *curses.ColorTheme {383 if theme != nil {383 dupe := *theme384 return &dupe384 dupe := *theme385 return &dupe386 }387 return nil388}389390func parseTheme(defaultTheme *curses.ColorTheme, str string) *curses.ColorTheme {391 theme := dupeTheme(defaultTheme)
12 unmodified lines
404 errorExit("invalid color specification: " + str)405 }406 // Color is disabled407 if theme == nil {405 errorExit("colors disabled; cannot customize colors")408 continue409 }410411 pair := strings.Split(str, ":")412 if len(pair) != 2 {
483 unmodified lines