Skip to content

Commit 7ce15e4

Browse files
committed
Highlight the paren under the cursor in a different color and hide the cursor.
1 parent 37d4750 commit 7ce15e4

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

bpython/cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1671,7 +1671,7 @@ def reprint_line(lineno, s, to_replace=[]):
16711671
if token is Token.Punctuation:
16721672
if value in '({[':
16731673
if under_cursor:
1674-
tokens[i] = (Parenthesis, value)
1674+
tokens[i] = (Parenthesis.UnderCursor, value)
16751675
# Push marker on the stack
16761676
stack.append(Parenthesis)
16771677
else:
@@ -1688,7 +1688,7 @@ def reprint_line(lineno, s, to_replace=[]):
16881688
tokens[i] = (Parenthesis, value)
16891689
break
16901690
elif under_cursor:
1691-
tokens[i] = (Parenthesis, value)
1691+
tokens[i] = (Parenthesis.UnderCursor, value)
16921692
(line, i, opening) = opening
16931693
screen_line = y - len(self.buffer) + line
16941694
if line == len(self.buffer):

bpython/formatter.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
# Pygments really kicks ass, it made it really easy to
2525
# get the exact behaviour I wanted, thanks Pygments.:)
2626

27+
import curses
2728
from pygments.formatter import Formatter
2829
from pygments.token import Keyword, Name, Comment, String, Error, \
2930
Number, Operator, Generic, Token, Whitespace, Literal, Punctuation
@@ -70,6 +71,7 @@
7071
Token: 'token',
7172
Whitespace: 'background',
7273
Parenthesis: 'punctuation',
74+
Parenthesis.UnderCursor: 'operator'
7375
}
7476

7577

@@ -99,10 +101,14 @@ def __init__(self, color_scheme, **options):
99101

100102
def format(self, tokensource, outfile):
101103
o = ''
104+
curses.curs_set(1)
102105
for token, text in tokensource:
103106
if text == '\n':
104107
continue
105108

109+
if token is Parenthesis.UnderCorsor:
110+
curses.curs_set(0)
111+
106112
if token in self.f_strings:
107113
o += "%s\x03%s\x04" % (self.f_strings[token], text )
108114
else:

0 commit comments

Comments
 (0)