How to use the ptpython.completer.PythonCompleter function in ptpython

To help you get started, we’ve selected a few ptpython examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jonathanslenders / ptpdb / ptpdb / __init__.py View on Github external
self.cli.buffers[DEFAULT_BUFFER].document = Document('')

        # Select the current frame of the stack.
        for i, (frame, lineno) in enumerate(self.stack):
            if frame is self.curframe:
                self.callstack_selected_frame = i
                break

        # Set up a new completer and validator for the new grammar.
        g = self._create_grammar()

        self.completer = GrammarCompleter(g, completers={
            'enabled_breakpoint': BreakPointListCompleter(only_enabled=True),
            'disabled_breakpoint': BreakPointListCompleter(only_disabled=True),
            'alias_name': AliasCompleter(self),
            'python_code': PythonCompleter(lambda: self.curframe.f_globals, lambda: self.curframe.f_locals),
            'breakpoint': BreakPointListCompleter(),
            'pdb_command': PdbCommandsCompleter(self),
            'python_file': PythonFileCompleter(),
            'python_function': PythonFunctionCompleter(self),
        })
        self.validator = GrammarValidator(g, {
            'python_code': PythonValidator()
        })

        # Make sure not to start in Vi navigation mode.
        self.python_input.key_bindings_manager.reset(self.cli)
        self.cli.buffers[DEFAULT_BUFFER].reset()

        def pre_run():
            self._source_code_window.vertical_scroll = 100000 # source_code_doc.line_count
github parttimenerd / temci / temci / scripts / init.py View on Github external
def prompt_python(msg: str, get_globals: t.Callable[[str], t.Any], get_locals: t.Callable[[str], t.Any]) -> str:
    """
    Prompt for python code.

    :param get_globals: function that returns the global variables
    :param get_locals: function that returns the local variables
    :return: user input
    """
    from ptpython.completer import PythonCompleter
    from pygments.lexers.python import Python3Lexer
    python_completer = PythonCompleter(get_globals, get_locals)
    return prompt(msg, multiline=True, mouse_support=True, lexer=PygmentsLexer(Python3Lexer),
                         completer=python_completer)
github prompt-toolkit / ptpython / ptpython / completer.py View on Github external
def __init__(self, get_globals, get_locals, get_enable_dictionary_completion):
        super(PythonCompleter, self).__init__()

        self.get_globals = get_globals
        self.get_locals = get_locals
        self.get_enable_dictionary_completion = get_enable_dictionary_completion

        self.dictionary_completer = DictionaryCompleter(get_globals, get_locals)

        self._path_completer_cache = None
        self._path_completer_grammar_cache = None
github prompt-toolkit / ptpython / ptpython / python_input.py View on Github external
input=None,
                 output=None,
                 color_depth=None,

                 # For internal use.
                 extra_key_bindings=None,
                 _completer=None, _validator=None,
                 _lexer=None, _extra_buffer_processors=None,
                 _extra_layout_body=None, _extra_toolbars=None,
                 _input_buffer_height=None):

        self.get_globals = get_globals or (lambda: {})
        self.get_locals = get_locals or self.get_globals

        self._completer = _completer or FuzzyCompleter(
            PythonCompleter(self.get_globals, self.get_locals,
                            lambda: self.enable_dictionary_completion),
            enable_fuzzy=Condition(lambda: self.enable_fuzzy_completion))
        self._validator = _validator or PythonValidator(self.get_compiler_flags)
        self._lexer = _lexer or PygmentsLexer(PythonLexer)

        if history_filename:
            self.history = ThreadedHistory(FileHistory(history_filename))
        else:
            self.history = InMemoryHistory()

        self._input_buffer_height = _input_buffer_height
        self._extra_layout_body = _extra_layout_body or []
        self._extra_toolbars = _extra_toolbars or []
        self._extra_buffer_processors = _extra_buffer_processors or []

        self.extra_key_bindings = extra_key_bindings or KeyBindings()