How to use the readchar.key.CTRL_C 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 Kamik423 / cutie / test / test_select.py View on Github external
def test_keyboard_interrupt_ctrl_c_no_input(self, *m):
        with InputContext(readchar.key.CTRL_C):
            with self.assertRaises(KeyboardInterrupt):
                cutie.select(["foo"])
github Kamik423 / cutie / test / test_select.py View on Github external
def test_keyboard_interrupt_ctrl_c_selected(self, *m):
        with InputContext(readchar.key.DOWN, readchar.key.CTRL_C):
            with self.assertRaises(KeyboardInterrupt):
                cutie.select(["foo"], selected_index=0)
github magmax / python-inquirer / tests / integration / console_render / test_list.py View on Github external
def test_ctrl_c_breaks_execution(self):
        stdin_array = [key.CTRL_C]
        stdin = helper.event_factory(*stdin_array)
        message = 'Foo message'
        variable = 'Bar variable'

        question = questions.List(variable, message)

        sut = ConsoleRender(event_generator=stdin)
        with self.assertRaises(KeyboardInterrupt):
            sut.render(question)
github magmax / python-inquirer / tests / integration / console_render / test_checkbox.py View on Github external
def test_ctrl_c_breaks_execution(self):
        stdin_array = [key.CTRL_C]
        stdin = helper.event_factory(*stdin_array)
        message = 'Foo message'
        variable = 'Bar variable'
        choices = ['foo', 'bar', 'bazz']

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

        sut = ConsoleRender(event_generator=stdin)
        with self.assertRaises(KeyboardInterrupt):
            sut.render(question)
github Kamik423 / cutie / test / test_prompt_yes_or_no.py View on Github external
def test_evaluate_written_input_no_case_sensitive(self, mock_print):
        expected_calls = (('\x1b[3A\r\x1b[Kfoo (Y/N) no',), {"end": '', "flush": True},)

        with InputContext("n", "o", readchar.key.CTRL_C):
            res = None
            with self.assertRaises(KeyboardInterrupt):
                res = cutie.prompt_yes_or_no("foo", has_to_match_case=True)
            self.assertIsNone(res)
            self.assertEqual(mock_print.call_args_list[-1], expected_calls)
github Kamik423 / cutie / test / test_prompt_yes_or_no.py View on Github external
print_call("No", "selected"),
                            (('\x1b[3A\r\x1b[Kfoo (Y/N) ',), {"end": '', "flush": True},),
                            (tuple(),),
                            print_call("Yes"),
                            print_call("No"),
                            (('\x1b[3A\r\x1b[Kfoo (Y/N) f',), {"end": '', "flush": True},),
                            (tuple(),),
                            print_call("Yes"),
                            print_call("No"),
                            (('\x1b[3A\r\x1b[Kfoo (Y/N) fo',), {"end": '', "flush": True},),
                            (tuple(),),
                            print_call("Yes"),
                            print_call("No"),
                            (('\x1b[3A\r\x1b[Kfoo (Y/N) foo',), {"end": '', "flush": True},),
                        ]
        with InputContext("f", "o", "o", readchar.key.CTRL_C):
            with self.assertRaises(KeyboardInterrupt):
                cutie.prompt_yes_or_no("foo")
            self.assertEqual(mock_print.call_args_list, expected_calls)
github magmax / python-inquirer / inquirer / render / console / _checkbox.py View on Github external
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 = []
            for x in self.selection:
                value = self.question.choices[x]
                result.append(getattr(value, 'value', value))
            raise errors.EndOfInput(result)
        elif pressed == key.CTRL_C:
            raise KeyboardInterrupt()
github magmax / python-inquirer / inquirer / render / console / _list.py View on Github external
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()
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)

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