How to use the readchar.key 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 / integration / console_render / test_confirm.py View on Github external
def test_yes_as_default(self):
        stdin = helper.event_factory(key.ENTER)
        message = 'Foo message'
        variable = 'Bar variable'
        expected = True

        question = questions.Confirm(variable,
                                     message=message,
                                     default=True)

        sut = ConsoleRender(event_generator=stdin)
        result = sut.render(question)

        self.assertEqual(expected, result)
        self.assertInStdout(message)
        self.assertInStdout('(Y/n)')
github magmax / python-inquirer / tests / acceptance / test_checkbox.py View on Github external
def test_unselect_with_arrows(self):
        self.sut.send(key.DOWN)
        self.sut.send(key.LEFT)
        self.sut.send(key.ENTER)
        self.sut.expect("{'interests': \['Computers'\]}.*", timeout=1)  # noqa
github magmax / python-inquirer / tests / integration / test_console_render.py View on Github external
def test_can_move(self):
        stdin = (key.DOWN
                 + key.DOWN
                 + key.UP
                 + key.SPACE
                 + key.ENTER)
        message = 'Foo message'
        variable = 'Bar variable'
        choices = ['foo', 'bar', 'bazz']

        sys.stdin = StringIO(stdin)
        question = questions.Checkbox(variable, message, choices=choices)

        sut = ConsoleRender(key_generator=fake_key_generator)
        result = sut.render(question)

        self.assertEqual(['bar'], result)
github t0thkr1s / revshellgen / revshellgen.py View on Github external
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
github magmax / python-inquirer / inquirer / render / console / _list.py View on Github external
if pressed == key.UP:
            if question.carousel and self.current == 0:
                self.current = len(question.choices) - 1
            else:
                self.current = max(0, self.current - 1)
            return
        if pressed == key.DOWN:
            if question.carousel and self.current == len(question.choices) - 1:
                self.current = 0
            else:
                self.current = min(
                    len(self.question.choices) - 1,
                    self.current + 1
                )
            return
        if pressed == key.ENTER:
            value = self.question.choices[self.current]
            raise errors.EndOfInput(getattr(value, 'value', value))

        if pressed == key.CTRL_C:
            raise KeyboardInterrupt()

readchar

Library to easily read single chars and key strokes

MIT
Latest version published 18 days ago

Package Health Score

88 / 100
Full package analysis

Similar packages