How to use the readchar.key.ENTER 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_list.py View on Github external
def test_all_choices_are_shown(self):
        stdin = helper.event_factory(key.ENTER)
        message = 'Foo message'
        variable = 'Bar variable'
        choices = ['foo', 'bar', 'bazz']

        question = questions.List(variable, message, choices=choices)

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

        self.assertInStdout(message)
        for choice in choices:
            self.assertInStdout(choice)
github magmax / python-inquirer / tests / acceptance / test_checkbox.py View on Github external
def test_default_input(self):
        self.sut.send(key.ENTER)
        self.sut.expect("{'interests': \['Computers', 'Books'\]}.*", timeout=1)  # noqa
github magmax / python-inquirer / tests / integration / console_render / test_confirm.py View on Github external
def test_no_as_default(self):
        stdin = helper.event_factory(key.ENTER)
        message = 'Foo message'
        variable = 'Bar variable'
        expected = False

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

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

        self.assertEqual(expected, result)
        self.assertInStdout(message)
        self.assertInStdout('(y/N)')
github Kamik423 / cutie / test / test_select.py View on Github external
'UP',
                    'DOWN',
                    'ENTER',
                    'CTRL_C',
                    'CTRL_D'
                    ]
        all_keys = [getattr(readchar.key, k) for k in dir(readchar.key) if k not in exclude]
        all_keys.extend(string.printable)
        expected_calls = [
                            (('',),),
                            (('\x1b[2A',),),
                            (('\x1b[K\x1b[1m[\x1b[32;1mx\x1b[0;1m]\x1b[0m foo',),),
                        ]

        for key in all_keys:
            with InputContext(readchar.key.DOWN, key, readchar.key.ENTER):
                selindex = cutie.select(["foo"])
                self.assertEqual(selindex, 0)
                self.assertEqual(mock_print.call_args_list[:3], expected_calls)
                mock_print.reset_mock()
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 magmax / python-inquirer / tests / acceptance / test_password.py View on Github external
def test_default_input(self):
        self.sut.expect(".*What's.*", timeout=1)
        self.sut.send('abcde')
        self.sut.send(key.ENTER)
        self.sut.expect("{'password': 'abcde'}", timeout=1)
github Kamik423 / cutie / test / test_select_multiple.py View on Github external
def test_deselect_on_min_sufficient(self, mock_print):
        call_args = ["foo", "bar"]
        expected_calls = [
                            print_call("foo"),
                            print_call("bar", "selected"),
                            print_call(state="confirm-active"),
                            PRINT_CALL_END
                        ]
        with InputContext(" ", readchar.key.DOWN, readchar.key.DOWN, readchar.key.ENTER):
            selected_indices = cutie.select_multiple(call_args, minimal_count=1, ticked_indices=[0, 1])
            self.assertEqual(mock_print.call_args_list[-4:], expected_calls)
            self.assertEqual(selected_indices, [1])
github magmax / python-inquirer / inquirer / render / console / _confirm.py View on Github external
def process_input(self, pressed):
        if pressed == key.CTRL_C:
            raise KeyboardInterrupt()

        if pressed.lower() == key.ENTER:
            raise errors.EndOfInput(self.question.default)

        if pressed in 'yY':
            print(pressed)
            raise errors.EndOfInput(True)
        if pressed in 'nN':
            print(pressed)
            raise errors.EndOfInput(False)
github t0thkr1s / revshellgen / revshellgen.py View on Github external
'\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 4 days ago

Package Health Score

85 / 100
Full package analysis

Similar packages