Skip to content

Commit 3c6e4c2

Browse files
committed
add more friendly error on theme load fail, add support for "cI" colours (I
being 'inverted')
1 parent 63e1951 commit 3c6e4c2

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

bpython/cli.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1167,10 +1167,12 @@ def echo(self, s, redraw=True):
11671167
fg = rx.groups()[0]
11681168
bg = rx.groups()[1]
11691169
col_num = self._C[fg.lower()]
1170-
if bg:
1170+
if bg and bg != 'I':
11711171
col_num *= self._C[bg.lower()]
11721172

11731173
a = curses.color_pair(int(col_num) + 1)
1174+
if bg == 'I':
1175+
a = a | curses.A_REVERSE
11741176
s = re.sub('\x01[A-Za-z][A-Za-z]?', '', s)
11751177
if fg.isupper():
11761178
a = a | curses.A_BOLD

bpython/config.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import sys
23
from ConfigParser import ConfigParser, NoSectionError, NoOptionError
34
from itertools import chain
45
from bpython.keys import key_dispatch
@@ -65,16 +66,21 @@ def loadini(struct, configfile):
6566
}
6667
else:
6768
path = os.path.expanduser('~/.bpython/%s.theme' % (color_scheme_name,))
68-
load_theme(struct, path)
69+
load_theme(struct, path, configfile)
6970

7071

7172
# checks for valid key configuration this part still sucks
7273
for key in (struct.pastebin_key, struct.save_key):
7374
key_dispatch[key]
7475

75-
def load_theme(struct, path):
76+
def load_theme(struct, path, inipath):
7677
theme = CP()
77-
f = open(path, 'r')
78+
try:
79+
f = open(path, 'r')
80+
except (IOError, OSError), e:
81+
sys.stdout.write("Error loading theme file specified in '%s':\n%s\n" %
82+
(inipath, e))
83+
sys.exit(1)
7884
theme.readfp(f)
7985
struct.color_scheme = {}
8086
for k, v in chain(theme.items('syntax'), theme.items('interface')):

bpython/formatter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def __init__(self, color_scheme, **options):
9494
if k is Parenthesis:
9595
# FIXME: Find a way to make this the inverse of the current
9696
# background colour
97-
self.f_strings[k] += 'w'
97+
self.f_strings[k] += 'I'
9898
Formatter.__init__(self, **options)
9999

100100
def format(self, tokensource, outfile):

0 commit comments

Comments
 (0)