Skip to content

Commit 2073f4f

Browse files
committed
make colour scheme configurable. also fix quoting of strings in sample.ini
ini format apparently doesn't expect quotes (they'll be passed as part of the actual string)
1 parent 5550217 commit 2073f4f

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

bpython/cli.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1431,7 +1431,7 @@ def print_line(self, s, clr=False):
14311431
tokens = chain([(Token.String, value[3:])], tokens)
14321432
else:
14331433
tokens = PythonLexer().get_tokens(s)
1434-
o = format(tokens, BPythonFormatter())
1434+
o = format(tokens, BPythonFormatter(OPTS.color_scheme))
14351435
else:
14361436
o = s
14371437

@@ -1838,6 +1838,7 @@ def safeget(self, section, option, default):
18381838
OPTS.hist_file = config.safeget('general', 'hist_file', '~/.pythonhist')
18391839
OPTS.hist_length = config.safeget('general', 'hist_length', 100)
18401840
OPTS.flush_output = config.safeget('general', 'flush_output', True)
1841+
OPTS.color_scheme = config.safeget('general', 'color_scheme', 'dark')
18411842

18421843

18431844
class FakeDict(object):

bpython/formatter.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,12 @@ class BPythonFormatter(Formatter):
100100
See the Pygments source for more info; it's pretty
101101
straightforward."""
102102

103-
def __init__(self, **options):
103+
def __init__(self, color_scheme, **options):
104+
if color_scheme == "light":
105+
self.f_strings = f_strings_light
106+
else:
107+
self.f_strings = f_strings
108+
104109
Formatter.__init__(self, **options)
105110

106111
def format(self, tokensource, outfile):
@@ -109,10 +114,10 @@ def format(self, tokensource, outfile):
109114
if text == '\n':
110115
continue
111116

112-
if token in f_strings:
113-
o += "%s\x03%s\x04" % (f_strings[token], text )
117+
if token in self.f_strings:
118+
o += "%s\x03%s\x04" % (self.f_strings[token], text )
114119
else:
115-
o += "%s\x03%s\x04" % (f_strings[Token], text )
120+
o += "%s\x03%s\x04" % (self.f_strings[Token], text )
116121
outfile.write(o.rstrip())
117122

118123
# vim: sw=4 ts=4 sts=4 ai et

sample.ini

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
# This is a standard python .ini file
3-
# Valid values can be True, False, integer numbers, quoted strings
3+
# Valid values can be True, False, integer numbers, strings
44
# By default bpython will look for ~/.bpython.ini or you can specify a file as
55
# the first argument on the command line
66

@@ -18,12 +18,16 @@ syntax = True
1818
# when possible (default: True).
1919
arg_spec = True
2020

21-
# History file (default: "~/.pythonhist"):
22-
hist_file = "~/.pythonhist"
21+
# History file (default: ~/.pythonhist):
22+
hist_file = ~/.pythonhist
2323

2424
# Number of lines to store in history (set to 0 to disable) (default: 100):
2525
hist_len = 100
2626

2727
# Soft tab size (default: 4, see pep-8):
2828
tab_length = 4
2929

30+
# Colour scheme can be "dark" or "light" (for dark and light background
31+
# terminals) (default: dark)
32+
color_scheme = dark
33+

0 commit comments

Comments
 (0)