def _autocomplete(self, output, question, input_stream):
        """
        Autocomplete a question.

        :param output: An Output instance
        :type output: Output

        :param question: The question to ask
        :type question: Question

        :rtype: str
        """
        autocomplete = question.autocompleter_values

        ret = ''

        i = 0
        ofs = -1
        matches = [x for x in autocomplete]
        num_matches = len(matches)

        stty_mode = decode(subprocess.check_output(['stty', '-g'])).rstrip('\n')

        # Disable icanon (so we can fread each keypress) and echo (we'll do echoing here instead)
        subprocess.check_output(['stty', '-icanon', '-echo'])

        # Add highlighted text style
        output.get_formatter().set_style('hl', OutputFormatterStyle('black', 'white'))

        # Read a keypress
        while True:
            c = input_stream.read(1)

            # Backspace character
            if c == '\177':
                if num_matches == 0 and i != 0:
                    i -= 1
                    # Move cursor backwards
                    output.write('\033[1D')

                if i == 0:
                    ofs = -1
                    matches = [x for x in autocomplete]
                    num_matches = len(matches)
                else:
                    num_matches = 0

                # Pop the last character off the end of our string
                ret = ret[:i]
            # Did we read an escape sequence
            elif c == '\033':
                c += input_stream.read(2)

                # A = Up Arrow. B = Down Arrow
                if c[2] == 'A' or c[2] == 'B':
                    if c[2] == 'A' and ofs == -1:
                        ofs = 0

                    if num_matches == 0:
                        continue

                    ofs += -1 if c[2] == 'A' else 1
                    ofs = (num_matches + ofs) % num_matches
            elif ord(c) < 32:
                if c == '\t' or c == '\n':
                    if num_matches > 0 and ofs != -1:
                        ret = matches[ofs]
                        # Echo out remaining chars for current match
                        output.write(ret[i:])
                        i = len(ret)

                    if c == '\n':
                        output.write(c)
                        break

                    num_matches = 0

                continue
            else:
                output.write(c)
                ret += c
                i += 1

                num_matches = 0
                ofs = 0

                for value in autocomplete:
                    # If typed characters match the beginning chunk of value (e.g. [AcmeDe]moBundle)
                    if value.startswith(ret) and i != len(value):
                        num_matches += 1
                        matches[1 - num_matches] = value

            # Erase characters from cursor to end of line
            output.write('\033[K')

            if num_matches > 0 and ofs != -1:
                # Save cursor position
                output.write('\0337')
                # Write highlighted text
                output.write('<hl>' + matches[ofs][i:] + '</hl>')
                # Restore cursor position
                output.write('\0338')

        subprocess.call(['stty', '%s' % decode(stty_mode)])

        return ret
dataset/ETHPy150Open sdispater/cleo/cleo/helpers/question_helper.py/QuestionHelper._autocomplete/swapped operands of `-`