예제 #1
0
    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))
예제 #2
0
    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))
예제 #3
0
 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
예제 #4
0
 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
예제 #5
0
 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 = ""
예제 #6
0
 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
예제 #7
0
 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()
예제 #8
0
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
예제 #9
0
 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
     )
예제 #10
0
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")
예제 #11
0
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
예제 #12
0
    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
        )
예제 #13
0
    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()
예제 #14
0
 def __init__(self, **kwargs):
     self.completer = Completer()
     super().__init__(**kwargs)
예제 #15
0
def completer():
    return Completer()
예제 #16
0
파일: plugin.py 프로젝트: sthagen/xonsh
def completer_obj():
    return Completer()