How to use the readchar.key.DOWN function in readchar

To help you get started, we’ve selected a few readchar 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 magmax / python-inquirer / tests / acceptance / test_list.py View on Github external
def test_change_selection(self):
        self.sut.send(key.DOWN)
        self.sut.expect('Micro.*', timeout=1)
        self.sut.send(key.ENTER)
        self.sut.expect("{'size': 'Large'}.*", timeout=1)
github magmax / python-inquirer / tests / acceptance / test_checkbox.py View on Github external
def test_select_one_more(self):
        self.sut.send(key.DOWN)
        self.sut.send(key.DOWN)
        self.sut.send(key.SPACE)
        self.sut.send(key.DOWN)
        self.sut.send(key.SPACE)
        self.sut.send(key.ENTER)
        self.sut.expect(
            "{'interests': \['Computers', 'Books', 'Science', 'Nature'\]}.*",  # noqa
            timeout=1
        )
github Kamik423 / cutie / test / test_select_multiple.py View on Github external
def test_move_down(self, mock_print):
        call_args = ["foo", "bar"]
        expected_calls = [
                            print_call("foo"),
                            print_call("bar", "active"),
                            print_call("", "caption"),
                            PRINT_CALL_END
                        ]
        with InputContext(readchar.key.DOWN, "\r"):
            cutie.select_multiple(call_args, hide_confirm=True)
        self.assertEqual(mock_print.call_args_list[-4:], expected_calls)
github magmax / python-inquirer / tests / integration / console_render / test_password.py View on Github external
def test_cursor_movement(self):
        stdin_array = [
            'a',
            key.UP,
            'b',
            key.DOWN,
            'c',
            key.LEFT,
            'd',
            key.RIGHT,
            'e',
            key.ENTER,
            ]
        stdin = helper.event_factory(*stdin_array)
        message = 'Foo message'
        variable = 'Bar variable'

        question = questions.Password(variable, message)

        sut = ConsoleRender(event_generator=stdin)
        result = sut.render(question)
github Kamik423 / cutie / test / test_prompt_yes_or_no.py View on Github external
def test_write_keypress_to_terminal_resume_selection(self, mock_print):
        expected_calls = [
                            (tuple(),),
                            print_call("Yes", "selected"),
                            print_call("No"),
                            (('\x1b[3A\r\x1b[Kfoo (Y/N) Yes',), {"end": '', "flush": True},),
                            (('\x1b[K\n\x1b[K\n\x1b[K\n\x1b[3A',),),
                        ]
        with InputContext("f", readchar.key.DOWN, "\r"):
            self.assertTrue(cutie.prompt_yes_or_no("foo"))
            self.assertEqual(mock_print.call_args_list[-5:], expected_calls)
github Kamik423 / cutie / test / test_select.py View on Github external
def test_move_down(self, *m):
        with InputContext(readchar.key.DOWN, "\r"):
            args_list = ["foo", "bar"]
            selindex = cutie.select(args_list)
            self.assertEqual(selindex, 1)
github magmax / python-inquirer / tests / acceptance / test_checkbox.py View on Github external
def test_select_with_arrows(self):
        self.sut.send(key.DOWN)
        self.sut.send(key.DOWN)
        self.sut.send(key.RIGHT)
        self.sut.send(key.ENTER)
        self.sut.expect(
            "{'interests': \['Computers', 'Books', 'Science'\]}.*",  # noqa
            timeout=1
        )
github mmeyer724 / sshmenu / sshmenu / sshmenu.py View on Github external
line = (digits_format_specifier + '. %s ') % (index + 1, target['desc'].ljust(longest_line))
                    if index == selected_target:
                        puts(colored.green(' -> %s' % line))
                    else:
                        puts(colored.white('    %s' % line))

        # Hang until we get a keypress
        key = readchar.readkey()

        if key == readchar.key.UP or key == 'k' and num_targets > 0:
            # Ensure the new selection would be valid & reset number input buffer
            if (selected_target - 1) >= 0:
                selected_target -= 1
            number_buffer = []

        elif key == readchar.key.DOWN or key == 'j' and num_targets > 0:
            # Ensure the new selection would be valid & reset number input buffer
            if (selected_target + 1) <= (num_targets - 1):
                selected_target += 1
            number_buffer = []

        elif key == 'g':
            # Go to top & reset number input buffer
            selected_target = 0
            number_buffer = []

        elif key == 'G':
            # Go to bottom & reset number input buffer
            selected_target = num_targets - 1
            number_buffer = []

        # Check if key is a number
github magmax / python-inquirer / inquirer / render / console / _checkbox.py View on Github external
def process_input(self, pressed):
        if pressed == key.UP:
            self.current = max(0, self.current - 1)
            return
        elif pressed == key.DOWN:
            self.current = min(len(self.question.choices) - 1,
                               self.current + 1)
            return
        elif pressed == key.SPACE:
            if self.current in self.selection:
                self.selection.remove(self.current)
            else:
                self.selection.append(self.current)
        elif pressed == key.LEFT:
            if self.current in self.selection:
                self.selection.remove(self.current)
        elif pressed == key.RIGHT:
            if self.current not in self.selection:
                self.selection.append(self.current)
        elif pressed == key.ENTER:
            result = []
github t0thkr1s / revshellgen / revshellgen.py View on Github external
selected_index: int = 0) -> int:
    print('\n' * (len(options) - 1))
    while True:
        print(f'\033[{len(options) + 1}A')
        for i, option in enumerate(options):
            print('\033[K{}{}'.format(
                '\033[1m[\033[32;1m x \033[0;1m]\033[0m ' if i == selected_index else
                '\033[1m[   ]\033[0m ', option))
        keypress = readchar.readkey()
        if keypress == readchar.key.UP:
            new_index = selected_index
            while new_index > 0:
                new_index -= 1
                selected_index = new_index
                break
        elif keypress == readchar.key.DOWN:
            new_index = selected_index
            while new_index < len(options) - 1:
                new_index += 1
                selected_index = new_index
                break
        elif keypress == readchar.key.ENTER:
            break
        elif keypress == readchar.key.CTRL_C:
            raise KeyboardInterrupt
    return selected_index

readchar

Library to easily read single chars and key strokes

MIT
Latest version published 1 month ago

Package Health Score

85 / 100
Full package analysis

Similar packages