mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 16:34:47 +01:00
attempted fix for ptk not having a completer attribute
This commit is contained in:
parent
ee66cabb1b
commit
efc5412b7c
3 changed files with 26 additions and 21 deletions
|
@ -114,8 +114,7 @@ class BaseShell(object):
|
|||
super().__init__()
|
||||
self.execer = execer
|
||||
self.ctx = ctx
|
||||
if kwargs.get('completer', True):
|
||||
self.completer = Completer()
|
||||
self.completer = Completer() if kwargs.get('completer', True) else None
|
||||
self.buffer = []
|
||||
self.need_more_lines = False
|
||||
self.mlprompt = None
|
||||
|
|
|
@ -25,21 +25,24 @@ class PromptToolkitCompleter(Completer):
|
|||
|
||||
# Only generate completions when the user hits tab.
|
||||
if complete_event.completion_requested:
|
||||
line = document.current_line.lstrip()
|
||||
endidx = document.cursor_position_col
|
||||
begidx = line[:endidx].rfind(' ') + 1 if line[:endidx].rfind(' ') >= 0 else 0
|
||||
prefix = line[begidx:endidx]
|
||||
completions, l = self.completer.complete(prefix,
|
||||
line,
|
||||
begidx,
|
||||
endidx,
|
||||
self.ctx)
|
||||
if len(completions) <= 1:
|
||||
pass
|
||||
elif len(os.path.commonprefix(completions)) <= len(prefix):
|
||||
self.reserve_space()
|
||||
for comp in completions:
|
||||
yield Completion(comp, -l)
|
||||
if self.completer is None:
|
||||
yield from []
|
||||
else:
|
||||
line = document.current_line.lstrip()
|
||||
endidx = document.cursor_position_col
|
||||
begidx = line[:endidx].rfind(' ') + 1 if line[:endidx].rfind(' ') >= 0 else 0
|
||||
prefix = line[begidx:endidx]
|
||||
completions, l = self.completer.complete(prefix,
|
||||
line,
|
||||
begidx,
|
||||
endidx,
|
||||
self.ctx)
|
||||
if len(completions) <= 1:
|
||||
pass
|
||||
elif len(os.path.commonprefix(completions)) <= len(prefix):
|
||||
self.reserve_space()
|
||||
for comp in completions:
|
||||
yield Completion(comp, -l)
|
||||
|
||||
def reserve_space(self):
|
||||
cli = builtins.__xonsh_shell__.shell.prompter.cli
|
||||
|
|
|
@ -194,10 +194,13 @@ class ReadlineShell(BaseShell, Cmd):
|
|||
rl_completion_suppress_append() # this needs to be called each time
|
||||
mline = line.partition(' ')[2]
|
||||
offs = len(mline) - len(text)
|
||||
x = [(i[offs:] if " " in i[:-1] else i)
|
||||
for i in self.completer.complete(text, line,
|
||||
begidx, endidx,
|
||||
ctx=self.ctx)[0]]
|
||||
if self.completer is None:
|
||||
x = []
|
||||
else:
|
||||
x = [(i[offs:] if " " in i[:-1] else i)
|
||||
for i in self.completer.complete(text, line,
|
||||
begidx, endidx,
|
||||
ctx=self.ctx)[0]]
|
||||
return x
|
||||
|
||||
# tab complete on first index too
|
||||
|
|
Loading…
Add table
Reference in a new issue