def complete( self, line: xcli.Annotated["list[str]", xcli.Arg(nargs="...")], prefix: "str | None" = None, ): """Output the completions to stdout Parameters ---------- line pass the CLI arguments as if they were typed prefix : -p, --prefix word at cursor Examples -------- To get completions such as `git checkout` $ completer complete --prefix=check git """ from xonsh.completer import Completer completer = Completer() completions, prefix_length = completer.complete_line(" ".join(line), prefix=prefix) self.out(f"Prefix Length: {prefix_length}") for comp in completions: self.out(repr(comp))
def complete( self, line: str, ): """Output the completions to stdout Parameters ---------- line pass the CLI arguments as if they were typed prefix : -p, --prefix word at cursor Examples -------- To get completions such as ``pip install`` $ completer complete 'pip in' To get ``pip`` sub-commands, pass the command with a space at the end $ completer complete 'pip ' """ from xonsh.completer import Completer completer = Completer() completions, prefix_length = completer.complete_line(line) self.out(f"Prefix Length: {prefix_length}") for comp in completions: self.out(repr(comp))
def __init__(self, execer, ctx, **kwargs): super().__init__(**kwargs) self.execer = execer self.ctx = ctx self.completer = Completer() self.buffer = [] self.need_more_lines = False self.mlprompt = None
def __init__(self, execer, ctx, **kwargs): super().__init__() self.execer = execer self.ctx = ctx self.completer = Completer() if kwargs.get('completer', True) else None self.buffer = [] self.need_more_lines = False self.mlprompt = None self._styler = DefaultNotGiven
def __init__(self, execer, ctx, **kwargs): super().__init__() self.execer = execer self.ctx = ctx self.completer = Completer() if kwargs.get("completer", True) else None self.buffer = [] self.need_more_lines = False self.mlprompt = None self._styler = DefaultNotGiven self.prompt_formatter = PromptFormatter() self.accumulated_inputs = ""
def __init__(self, execer, ctx, **kwargs): super().__init__(**kwargs) self.execer = execer self.ctx = ctx self.completer = Completer() self.buffer = [] self.need_more_lines = False self.mlprompt = None if HAVE_PYGMENTS: env = builtins.__xonsh_env__ self.styler = XonshStyle(env.get('XONSH_COLOR_STYLE')) else: self.styler = None
def __init__(self, completekey='tab', stdin=None, stdout=None, ctx=None): super(Shell, self).__init__(completekey=completekey, stdin=stdin, stdout=stdout) self.execer = Execer() env = builtins.__xonsh_env__ self.ctx = ctx if ctx is not None else \ xonshrc_context(rcfile=env.get('XONSHRC', None), execer=self.execer) self.completer = Completer() self.buffer = [] self.need_more_lines = False self.mlprompt = None setup_readline()
def check_completer(xession): """Helper function to run completer and parse the results as set of strings""" completer = Completer() def _factory(line: str, prefix="", send_original=False): completions, _ = completer.complete_line(line, prefix=prefix) values = {getattr(i, "value", i).strip() for i in completions} if send_original: # just return the bare completions without appended-space for easier assertions return values, completions return values return _factory
def __init__(self, execer, ctx, **kwargs): super().__init__() self.execer = execer self.ctx = ctx self.completer = Completer() if kwargs.get("completer", True) else None self.buffer = [] self.need_more_lines = False self.src_starts_with_space = False self.mlprompt = None self._styler = DefaultNotGiven self.prompt_formatter = PromptFormatter() self.accumulated_inputs = "" self.precwd = ( None # The current working directory just before execution of the line )
def test_skipper_arg(completion_context_parse, xession, monkeypatch): monkeypatch.setattr(xession.shell.shell, "completer", Completer(), raising=False) bash_completer_mock = Mock() monkeypatch.setattr(xession, "completers", {"bash": bash_completer_mock}) bash_completer_mock.return_value = {"--count "} assert "--count " in completions_from_result( complete_skipper(completion_context_parse("sudo grep --coun", 16))) call_args = bash_completer_mock.call_args[0] assert len(call_args) == 1 context = call_args[0] assert isinstance(context, CompletionContext) assert context.command == CommandContext(args=(CommandArg("grep"), ), arg_index=1, prefix="--coun")
def check_completer(xession): """Helper function to run completer and parse the results as set of strings""" comp = Completer() def _factory(line: str, prefix=""): line = line.strip() if prefix: begidx = len(line) + 1 endidx = begidx + len(prefix) line = " ".join([line, prefix]) else: line += " " begidx = endidx = len(line) completions, _ = comp.complete( prefix, line, begidx, endidx, cursor_index=len(line), multiline_text=line ) # just return the bare completions without appended-space for easier assertions return {getattr(i, "value", i).strip() for i in completions} return _factory
def __init__(self, execer, ctx, **kwargs): """ Notes ----- classes inheriting multiple base classes should call them explicitly as done for ``ReadlineShell`` """ self.execer = execer self.ctx = ctx self.completer = Completer() if kwargs.get("completer", True) else None self.buffer = [] self.need_more_lines = False self.src_starts_with_space = False self.mlprompt = None self._styler = DefaultNotGiven self.prompt_formatter = PromptFormatter() self.accumulated_inputs = "" self.precwd = ( None # The current working directory just before execution of the line )
def __init__(self, debug_level=0, session_id=None, config=None, **kwargs): """ Parameters ---------- debug_level : int, optional Integer from 0 (no debugging) to 3 (all debugging), default: 0. session_id : str or None, optional Unique string id representing the kernel session. If None, this will be replaced with a random UUID. config : dict or None, optional Configuration dictionary to start server with. BY default will search the command line for options (if given) or use default configuration. """ self.debug_level = debug_level self.session_id = str( uuid.uuid4()) if session_id is None else session_id self._parser = None self.config = self.make_default_config() if config is None else config self.exiting = False self.execution_count = 1 self.completer = Completer()
def __init__(self, **kwargs): self.completer = Completer() super().__init__(**kwargs)
def completer(): return Completer()
def completer_obj(): return Completer()