def __init__(self, event_generator=None, theme=None, *args, **kwargs): super(ConsoleRender, self).__init__(*args, **kwargs) self._event_gen = event_generator or events.KeyEventGenerator() self.terminal = Terminal() self._previous_error = None self._position = 0 self._theme = theme or themes.Default()
def prompt(questions, render=None, answers=None, theme=themes.Default(), raise_keyboard_interrupt=False): render = render or ConsoleRender(theme=theme) answers = answers or {} try: for question in questions: answers[question.name] = render.render(question, answers) return answers except KeyboardInterrupt: if raise_keyboard_interrupt: raise print("") print("Cancelled by user") print("")
return ExtendedList return super().render_factory(question_type) class ExtendedList(List): def process_input(self, pressed): # vi style if pressed in ("k"): pressed = key.UP elif pressed in ("j"): pressed = key.DOWN elif pressed == "q": pressed = key.CTRL_C # effect (rendering) super().process_input(pressed) questions = [ inquirer.List( "size", message="What size do you need?", choices=["Jumbo", "Large", "Standard", "Medium", "Small", "Micro"], carousel=True, ) ] answers = inquirer.prompt(questions, render=ExtendedConsoleRender(theme=themes.Default())) print(answers)