def process_input(self, pressed): question = self.question if pressed == key.UP: if question.carousel and self.current == 0: self.current = len(question.choices) - 1 return True else: # this should be determined before changing `self.current` need_to_rerender = self.current != 0 self.current = max(0, self.current - 1) return need_to_rerender if pressed == key.DOWN: if question.carousel and self.current == len(question.choices) - 1: self.current = 0 return True else: # this should be determined before changing `self.current` need_to_rerender = self.current != (self.n_current_choices - 1) self.current = min( # len(self.question.choices) - 1, self.n_current_choices - 1, self.current + 1) return need_to_rerender if pressed == key.ENTER: if self.filtered_choices is not None: # We are under the search mode if len(self.filtered_choices) != 0: value = self.filtered_choices[self.current] else: raise errors.EndOfInput(None) else: value = self.question.choices[self.current] raise errors.EndOfInput(getattr(value, 'value', value)) # Search mode related if pressed == '/': if self.choices_searcher is None: # Searcher is no available, so that search mode is disabled. return False pattern = input('Enter pattern to search (enter "/q" to quit): ') self.search_pattern = pattern clear_code = self.terminal.move_up() + self.terminal.clear_eol() print(clear_code * 2) return True if pressed == key.CTRL_C: raise KeyboardInterrupt()
def process_input(self, pressed): if pressed == key.CTRL_C: raise KeyboardInterrupt() if pressed in (key.CR, key.LF, key.ENTER): data = editor.edit(contents=self.question.default or "") raise errors.EndOfInput(data.decode("utf-8")) raise errors.ValidationError("You have pressed unknown key! " "Press <enter> to open editor or " "CTRL+C to exit.")
def process_input(self, pressed): if pressed == key.CTRL_C: raise KeyboardInterrupt() if pressed in (key.CR, key.LF, key.ENTER): data = editor.edit( filename=self.default_filename, # added by us contents=self.question.default or '') raise errors.EndOfInput(data.decode('utf-8')) raise errors.ValidationError( 'You have pressed unknown key! Press <enter> to open ' 'editor or CTRL+C to exit.')
def process_input(self, pressed): question = self.question 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)) raise errors.EndOfInput(self.question.choices[self.current]) if pressed == key.CTRL_C: raise KeyboardInterrupt()
def process_input(self, pressed): if pressed == key.CTRL_C: raise KeyboardInterrupt() if pressed == key.ENTER: raise errors.EndOfInput(self.current) if pressed == key.BACKSPACE: if len(self.current): self.current = self.current[:-1] return if len(pressed) != 1: return self.current += pressed
def process_input(self, pressed): if pressed == key.CTRL_C: raise KeyboardInterrupt() if pressed in (key.CR, key.LF, key.ENTER): raise errors.EndOfInput( self.question.normalize_value(self.current) ) if pressed == key.BACKSPACE: if len(self.current): self.current = self.current[:-1] return if len(pressed) != 1: return self.current += pressed