X Tutup
Skip to content

Commit fea3d8d

Browse files
committed
simplify "bold" output - just use an upper case character, slightly change
default colours
1 parent 6afbe52 commit fea3d8d

File tree

2 files changed

+24
-28
lines changed

2 files changed

+24
-28
lines changed

bpython/cli.py

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def DEBUG(s):
135135

136136

137137
def get_color(name):
138-
return colors[OPTS.color_scheme[name]]
138+
return colors[OPTS.color_scheme[name].lower()]
139139

140140
def get_colpair(name):
141141
return curses.color_pair(get_color(name) + 1)
@@ -1099,17 +1099,18 @@ def echo(self, s, redraw=True):
10991099

11001100
a = get_colpair('output')
11011101
if '\x01' in s:
1102-
rx = re.search('\x01([a-z])([a-z]?)', s)
1102+
rx = re.search('\x01([A-Za-z])([A-Za-z]?)', s)
11031103
if rx:
1104-
p = self._C[rx.groups()[0]]
1105-
if rx.groups()[1]:
1106-
p *= self._C[rx.groups()[1]]
1107-
1108-
a = curses.color_pair(int(p) + 1)
1109-
s = re.sub('\x01[a-z][a-z]?', '', s)
1110-
if '\x02' in s:
1111-
a = a | curses.A_BOLD
1112-
s = s.replace('\x02', '')
1104+
fg = rx.groups()[0]
1105+
bg = rx.groups()[1]
1106+
col_num = self._C[fg.lower()]
1107+
if bg:
1108+
col_num *= self._C[bg.lower()]
1109+
1110+
a = curses.color_pair(int(col_num) + 1)
1111+
s = re.sub('\x01[A-Za-z][A-Za-z]?', '', s)
1112+
if fg.upper():
1113+
a = a | curses.A_BOLD
11131114
s = s.replace('\x03', '')
11141115
s = s.replace('\x01', '')
11151116

@@ -1925,33 +1926,30 @@ def loadini(configfile):
19251926
'string': 'g',
19261927
'error': 'r',
19271928
'number': 'g',
1928-
'operator': 'c',
1929-
'punctuation': 'y',
1929+
'operator': 'C',
1930+
'punctuation': 'c',
19301931
'token': 'g',
19311932
'background': 'k',
19321933
'output': 'w',
19331934
'main': 'c',
1934-
'prompt': 'r',
1935+
'prompt': 'y',
19351936
'prompt_more': 'g',
19361937
}
19371938
else:
19381939
path = os.path.expanduser('~/.bpython/%s.theme' % (color_scheme_name,))
1939-
# XXX ConfigParser doesn't raise an IOError if it tries to read a file
1940-
# that doesn't exist which isn't helpful to us:
1941-
if not os.path.isfile(path):
1942-
raise IOError("'%s' is not a readable file" % (path,))
1943-
load_theme(color_scheme_name)
1944-
1945-
def load_theme(name):
1946-
path = os.path.expanduser('~/.bpython/%s.theme' % (name,))
1940+
load_theme(path)
1941+
1942+
def load_theme(path):
19471943
theme = CP()
1948-
theme.read(path)
1944+
f = open(path, 'r')
1945+
theme.readfp(f)
19491946
OPTS.color_scheme = {}
19501947
for k, v in chain(theme.items('syntax'), theme.items('interface')):
19511948
if theme.has_option('syntax', k):
19521949
OPTS.color_scheme[k] = theme.get('syntax', k)
19531950
else:
19541951
OPTS.color_scheme[k] = theme.get('interface', k)
1952+
f.close()
19551953

19561954

19571955
class FakeDict(object):

bpython/formatter.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,10 @@
6969
Punctuation: 'punctuation',
7070
Token: 'token',
7171
Whitespace: 'background',
72+
Parenthesis: 'keyword',
7273
}
7374

74-
75+
7576
class BPythonFormatter(Formatter):
7677
"""This is the custom formatter for bpython.
7778
Its format() method receives the tokensource
@@ -89,10 +90,7 @@ class BPythonFormatter(Formatter):
8990
def __init__(self, color_scheme, **options):
9091
if not self.f_strings:
9192
for k, v in theme_map.iteritems():
92-
if color_scheme[v].isupper():
93-
self.f_strings[k] = '\x01%s\x02' % (color_scheme[v].lower(),)
94-
else:
95-
self.f_strings[k] = '\x01%s' % (color_scheme[v],)
93+
self.f_strings[k] = '\x01%s' % (color_scheme[v],)
9694
Formatter.__init__(self, **options)
9795

9896
def format(self, tokensource, outfile):

0 commit comments

Comments
 (0)
X Tutup