How to use the readchar.key.SPACE 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_checkbox.py View on Github external
def test_left_cursor_do_not_select(self):
        stdin_array = [key.SPACE, key.LEFT, key.LEFT, key.ENTER]
        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)
        result = sut.render(question)

        self.assertEqual([], result)
github magmax / python-inquirer / tests / integration / console_render / test_checkbox.py View on Github external
def test_deselection(self):
        stdin_array = [key.SPACE, key.SPACE, key.ENTER]
        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)
        result = sut.render(question)

        self.assertEqual([], result)
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_pre_answers.py View on Github external
def test_minimal_input(self):
        # user
        self.sut.expect("Please enter", timeout=1)
        self.sut.send('abcde')
        self.sut.send(key.ENTER)
        # password
        self.sut.expect("Please enter", timeout=1)
        self.sut.send('edcba')
        self.sut.send(key.ENTER)
        # repo
        self.sut.expect("Please enter", timeout=1)
        self.sut.send(key.ENTER)
        # topics
        self.sut.expect("Please define", timeout=1)
        self.sut.send(key.SPACE)
        self.sut.send(key.ENTER)
        # organization
        self.sut.expect("If this is", timeout=1)
        self.sut.send(key.ENTER)
        # correct
        self.sut.expect("This will delete", timeout=1)
        self.sut.send('y')

        # again

        # user
        self.sut.expect("Please enter", timeout=1)
        self.sut.send(key.ENTER)
        # password
        self.sut.expect("Please enter", timeout=1)
        self.sut.send(key.ENTER)
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 magmax / python-inquirer / tests / acceptance / test_checkbox.py View on Github external
def test_select_the_third(self):
        self.sut.send(key.DOWN)
        self.sut.send(key.DOWN)
        self.sut.send(key.SPACE)
        self.sut.send(key.ENTER)
        self.sut.expect(
            "{'interests': \['Computers', 'Books', 'Science'\]}.*", timeout=1)  # noqa
github Kamik423 / cutie / cutie.py View on Github external
init()


class DefaultKeys:
    """List of default keybindings.

    Attributes:
        interrupt(List[str]): Keys that cause a keyboard interrupt.
        select(List[str]): Keys that trigger list element selection.
        confirm(List[str]): Keys that trigger list confirmation.
        delete(List[str]): Keys that trigger character deletion.
        down(List[str]): Keys that select the element below.
        up(List[str]): Keys that select the element above.
    """
    interrupt: List[str] = [readchar.key.CTRL_C, readchar.key.CTRL_D]
    select: List[str] = [readchar.key.SPACE]
    confirm: List[str] = [readchar.key.ENTER]
    delete: List[str] = [readchar.key.BACKSPACE]
    down: List[str] = [readchar.key.DOWN, 'j']
    up: List[str] = [readchar.key.UP, 'k']


def get_number(
        prompt: str,
        min_value: Optional[float] = None,
        max_value: Optional[float] = None,
        allow_float: bool = True) -> float:
    """Get a number from user input.
    If an invalid number is entered the user will be prompted again.

    Args:
        prompt (str): The prompt asking the user to input.
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 = []
            for x in self.selection:
                value = self.question.choices[x]
                result.append(getattr(value, 'value', value))
            raise errors.EndOfInput(result)

readchar

Library to easily read single chars and key strokes

MIT
Latest version published 2 months ago

Package Health Score

88 / 100
Full package analysis

Similar packages