Skip to content

Commit 4e654ef

Browse files
add right arrow completion config option
1 parent 5de1f03 commit 4e654ef

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

bpython/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ def loadini(struct, configfile):
9090
'curtsies': {
9191
'list_above' : False,
9292
'fill_terminal' : False,
93+
'right_arrow_completion' : True,
9394
}})
9495
if not config.read(config_path):
9596
# No config file. If the user has it in the old place then complain
@@ -150,6 +151,7 @@ def loadini(struct, configfile):
150151

151152
struct.curtsies_list_above = config.getboolean('curtsies', 'list_above')
152153
struct.curtsies_fill_terminal = config.getboolean('curtsies', 'fill_terminal')
154+
struct.curtsies_right_arrow_completion = config.getboolean('curtsies', 'right_arrow_completion')
153155

154156
color_scheme_name = config.get('general', 'color_scheme')
155157

bpython/curtsiesfrontend/repl.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,8 @@ def process_event(self, e):
336336
self.update_completion()
337337
return
338338

339-
elif e in ("KEY_RIGHT") and self.cursor_offset == len(self.current_line):
339+
elif (e in ("KEY_RIGHT", '\x06') and self.config.curtsies_right_arrow_completion
340+
and self.cursor_offset == len(self.current_line)):
340341
self.current_line += self.current_suggestion
341342
self.cursor_offset = len(self.current_line)
342343
self.update_completion()
@@ -348,13 +349,15 @@ def process_event(self, e):
348349
# readline history commands
349350
elif e in ("KEY_UP",) + key_dispatch[self.config.up_one_line_key]:
350351
self.rl_history.enter(self.current_line)
351-
self.current_line = self.rl_history.back(False, search=True)
352+
self.current_line = self.rl_history.back(False,
353+
search=self.config.curtsies_right_arrow_completion)
352354
self.cursor_offset = len(self.current_line)
353355
self.update_completion()
354356

355357
elif e in ("KEY_DOWN",) + key_dispatch[self.config.down_one_line_key]:
356358
self.rl_history.enter(self.current_line)
357-
self.current_line = self.rl_history.forward(False, search=True)
359+
self.current_line = self.rl_history.forward(False,
360+
search=self.config.curtsies_right_arrow_completion)
358361
self.cursor_offset = len(self.current_line)
359362
self.update_completion()
360363
elif e in key_dispatch[self.config.search_key]: #TODO Not Implemented
@@ -664,6 +667,9 @@ def current_line_formatted(self):
664667
"""The colored current line (no prompt, not wrapped)"""
665668
if self.config.syntax:
666669
fs = bpythonparse(format(self.tokenize(self.current_line), self.formatter))
670+
if self.rl_history.saved_line in self.current_line:
671+
if self.config.curtsies_right_arrow_completion:
672+
fs = fmtfuncs.on_magenta(self.rl_history.saved_line).join(fs.split(self.rl_history.saved_line))
667673
logging.debug('Display line %r -> %r', self.current_line, fs)
668674
else:
669675
fs = fmtstr(self.current_line)
@@ -707,7 +713,10 @@ def current_cursor_line_without_suggestion(self):
707713

708714
@property
709715
def current_cursor_line(self):
710-
return self.current_cursor_line_without_suggestion + fmtfuncs.bold(fmtfuncs.dark((self.current_suggestion)))
716+
if self.config.curtsies_right_arrow_completion:
717+
return self.current_cursor_line_without_suggestion + fmtfuncs.bold(fmtfuncs.dark((self.current_suggestion)))
718+
else:
719+
return self.current_cursor_line_without_suggestion
711720

712721
@property
713722
def current_suggestion(self):

doc/sphinx/source/configuration-options.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,3 +295,15 @@ Default: False
295295

296296
When there is space above the current line, whether the suggestions list will be
297297
displayed there instead of below the current line.
298+
299+
right_arrow_completion
300+
^^^^^^^^^^^^^^^^^^^^^^
301+
Default: True
302+
303+
Full line suggestion and completion (like fish shell and many web browsers).
304+
305+
Full line completions are displayed under the cursor in gray.
306+
When the cursor is at the end of a line, pressing right arrow or ctrl-f will
307+
complete the full line.
308+
This option also turns on substring history search, highlighting the matching
309+
section in previous result.

0 commit comments

Comments
 (0)