Skip to content

Commit 4a6bb99

Browse files
committed
This closes #78
Make the theme-file reading code use the default values when a key is not found in the theme file. This solves bpython raising exceptions and bpython.gtk_ segfaulting over those exceptions
1 parent 3a295e0 commit 4a6bb99

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

bpython/config.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ def loadini(struct, configfile):
9595

9696
color_scheme_name = config.get('general', 'color_scheme')
9797

98-
if color_scheme_name == 'default':
99-
struct.color_scheme = {
98+
default_colors = {
10099
'keyword': 'y',
101100
'name': 'c',
102101
'comment': 'b',
@@ -113,16 +112,19 @@ def loadini(struct, configfile):
113112
'prompt': 'c',
114113
'prompt_more': 'g',
115114
}
115+
116+
if color_scheme_name == 'default':
117+
struct.color_scheme = default_colors
116118
else:
117119
path = os.path.expanduser('~/.bpython/%s.theme' % (color_scheme_name,))
118-
load_theme(struct, path, config_path)
120+
load_theme(struct, path, config_path, default_colors)
119121

120122
# checks for valid key configuration this part still sucks
121123
for key in (struct.pastebin_key, struct.save_key):
122124
key_dispatch[key]
123125

124126

125-
def load_theme(struct, path, inipath):
127+
def load_theme(struct, path, inipath, default_colors):
126128
theme = ConfigParser()
127129
try:
128130
f = open(path, 'r')
@@ -137,6 +139,11 @@ def load_theme(struct, path, inipath):
137139
struct.color_scheme[k] = theme.get('syntax', k)
138140
else:
139141
struct.color_scheme[k] = theme.get('interface', k)
142+
143+
# Check against default theme to see if all values are defined
144+
for k, v in default_colors.iteritems():
145+
if k not in chain(theme.items('syntax'), theme.items('interface')):
146+
struct.color_scheme[k] = v
140147
f.close()
141148

142149

0 commit comments

Comments
 (0)