Skip to content

Commit 5a0d9d6

Browse files
committed
Improve and fix the "under cursor" detection of paren highlighting.
1 parent cb4527e commit 5a0d9d6

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

bpython/cli.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,9 +1656,10 @@ def reprint_line(lineno, s, to_replace=[]):
16561656
self.scr.move(lineno, 4)
16571657
map(self.echo, o.split('\x04'))
16581658

1659-
y, x = self.scr.getyx()
1659+
y = self.scr.getyx()[0]
1660+
x = self.ix + len(s) - self.cpos
16601661
if not self.cpos:
1661-
x += 1
1662+
x -= 1
16621663
if self.highlighted_paren:
16631664
# Clear previous highlighted paren
16641665
reprint_line(*self.highlighted_paren)
@@ -1690,7 +1691,15 @@ def reprint_line(lineno, s, to_replace=[]):
16901691
tokens[i] = (Parenthesis, value)
16911692
break
16921693
elif under_cursor:
1693-
tokens[i] = (Parenthesis.UnderCursor, value)
1694+
if self.cpos:
1695+
tokens[i] = (Parenthesis.UnderCursor, value)
1696+
else:
1697+
# The cursor is at the end of line and
1698+
# next to the paren, so it doesn't reverse
1699+
# the paren. Therefore, we insert the
1700+
# Parenthesis token here instead of the
1701+
# Parenthesis.UnderCursor token.
1702+
tokens[i] = (Parenthesis, value)
16941703
(line, i, opening) = opening
16951704
screen_line = y - len(self.buffer) + line
16961705
if line == len(self.buffer):

bpython/formatter.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def __init__(self, color_scheme, **options):
9393
if not self.f_strings:
9494
for k, v in theme_map.iteritems():
9595
self.f_strings[k] = '\x01%s' % (color_scheme[v],)
96-
if k is Parenthesis or k is Parenthesis.UnderCursor:
96+
if k is Parenthesis:
9797
# FIXME: Find a way to make this the inverse of the current
9898
# background colour
9999
self.f_strings[k] += 'I'
@@ -106,9 +106,6 @@ def format(self, tokensource, outfile):
106106
if text == '\n':
107107
continue
108108

109-
if token is Parenthesis.UnderCursor:
110-
curses.curs_set(0)
111-
112109
if token in self.f_strings:
113110
o += "%s\x03%s\x04" % (self.f_strings[token], text )
114111
else:

0 commit comments

Comments
 (0)