Prompt a string with autocompletion

    :param complete: A function that returns a list of possible strings that
        should be completed on a given text.
        def complete(text: str) -> List[str]: ...
555193
def prompt_autocomplete(prompt, complete, default=None, contains_spaces=True, 
                        show_default=True, prompt_suffix=': ', color=None):
    

    def real_completer(text, state):
        possibilities = complete(text) + [None]

        if possibilities:
            return possibilities[state]
        return None

    readline.set_completer_delims('\t\n' + ' ' * (not contains_spaces))
    readline.parse_and_bind("tab: complete")
    readline.set_completer(real_completer)
    
    if default is not None and show_default:
        prompt += ' [%s]' % default

    prompt += prompt_suffix

    colors = {
        'red': Fore.RED,
        'blue': Fore.BLUE,
        'green': Fore.GREEN,
        'cyan': Fore.CYAN,
        'magenta': Fore.MAGENTA,
        'yellow': Fore.YELLOW,
        'white': Fore.WHITE,
        'black': Fore.LIGHTBLACK_EX
    }

    if color:
        prompt = colors[color.lower()] + prompt + Fore.RESET

    if default is not None:
        r = input(prompt)
    else:
        while True:
            r = input(prompt)
            if r:
                break

    r = r or default

    # remove the autocompletion before quitting for future input()
    readline.parse_and_bind('tab: self-insert')
    readline.set_completer(None)

    return r
133717
def complete(self, text):
        
        if self.use_main_ns:
            # In pydev this option should never be used
            raise RuntimeError('Namespace must be provided!')
            self.namespace = __main__.__dict__  # @UndefinedVariable

        if "." in text:
            return self.attr_matches(text)
        else:
            return self.global_matches(text)
717026
def complete_serialize(self, text, line, begidx, endidx):
        """"""

        opts = self.SERIALIZE_OPTS

        if not text:
            completions = opts
        else:
            completions = [f
                           for f in opts
                           if f.startswith(text)
                           ]
        return completions
54050
def complete(self):
        """"""
        if self._possible is None:
            self._possible = []
            for possible in self.names:
                c = Completion(self.context, self.names[possible], len(self.context.symbol))
                self._possible.append(c)

        return self._possible
334241
function(params, callback) {
      var t = this;
      if (typeof(params) !== 'string' || params.length < 1) {
        callback("Autocomplete paramter must be a nonzero string");
      }

      // Forward to the completion mechanism if it can be completed
      if (params.substr(-1).match(/([0-9])|([a-z])|([A-Z])|([_])/)) {
        t.repl.complete(params, callback);
      } else {
        // Return a no-op autocomplete
        callback(null, [[],'']);
      }
    }
1328583
def _complete_cases(self, text, line, istart, iend):
        """"""
        if text == "":
            return list(self.live.keys())
        else:
            return [c for c in self.live if c.startswith(text)]
941802
def complete_opt(self, text, line, begidx, endidx):
        
        tokens = line.split()
        if len(tokens) == 1:
            if text:
                return
            else:
                option = ""
        else:
            option = tokens[1]
        if len(tokens) == 1 or (len(tokens) == 2 and text):
            return [
                name[4:] + " " for name in dir(self) if name.startswith("opt_" + text)
            ]
        method = getattr(self, "complete_opt_" + option, None)
        if method is not None:
            return method(text, line, begidx, endidx)
133789
def generate_completions(event):
    
    """
    b = event.current_buffer

    # When already navigating through completions, select the next one.
    if b.complete_state:
        b.complete_next()
    else:
        event.cli.start_completion(insert_common_part=True, select_first=False)
169060
def complete(self, text, state):
        
        if text != self.text:
            self.matches = self.completelist(text)
            self.text = text
        try:
            return self.matches[state]
        except IndexError:
            return None
1295499
def complete_ls(self, text, *_):
        
        return [t + " " for t in self.engine.cached_descriptions if t.startswith(text)]
1076770
def complete_ls(self, text, line, begidx, endidx):
        """"""

        options = self.LS_OPTS

        if not text:
            completions = options
        else:
            completions = [f
                           for f in options
                           if f.startswith(text)
                           ]
        return completions
626636
def complete(self, text, state):
        
        if self.use_main_ns:
            self.namespace = __main__.__dict__
        if state == 0:
            self.matches = self.attr_matches(text)
        try:
            return self.matches[state]
        except IndexError:
            return None
1292665
def apply_completion(self, completion):
        
        assert isinstance(completion, Completion)

        # If there was already a completion active, cancel that one.
        if self.complete_state:
            self.go_to_completion(None)
        self.complete_state = None

        # Insert text from the given completion.
        self.delete_before_cursor(-completion.start_position)
        self.insert_text(completion.text)
101100
def complete(text, state):
    """"""
    global completion_results
    if state == 0:
        line = readline.get_line_buffer()
        if line.startswith(':'):
            # Control command completion
            completion_results = complete_control_command(line, text)
        else:
            if line.startswith('!') and text and line.startswith(text):
                dropped_exclam = True
                text = text[1:]
            else:
                dropped_exclam = False
            completion_results = []
            # Complete local paths
            completion_results += complete_local_path(text)
            # Complete from history
            l = len(text)
            completion_results += [w + ' ' for w in history_words if
                                   len(w) > l and w.startswith(text)]
            if readline.get_begidx() == 0:
                # Completing first word from $PATH
                completion_results += [w + ' ' for w in user_commands_in_path
                                           if len(w) > l and w.startswith(text)]
            completion_results = remove_dupes(completion_results)
            if dropped_exclam:
                completion_results = ['!' + r for r in completion_results]

    if state < len(completion_results):
        return completion_results[state]
    completion_results = None
    return None
1105548
def autocomplete_query(self, **kwargs):
        
        if not kwargs.get('text'):
            raise ValueError('Valid text (parameter "text") must be provided.')

        return self._query(AUTOCOMPLETE_API_URL, **kwargs)
75343
def complete(text, state):
    
    for cmd in COMMANDS:
        if cmd.startswith(text):
            if not state:
                return cmd
            else:
                state -= 1
403915
def complete_file(self, text, line, begidx, endidx):
        """"""

        opts = self.FILE_OPTS

        if not text:
            completions = opts
        else:
            completions = [f
                           for f in opts
                           if f.startswith(text)
                           ]
        return completions