Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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.current)
if pressed == key.BACKSPACE:
if self.current and self.cursor_offset != len(self.current):
if self.cursor_offset > 0:
self.current = (self.current[:-self.cursor_offset - 1] +
self.current[-self.cursor_offset:])
else:
self.current = self.current[:-1]
elif pressed == key.LEFT:
if self.cursor_offset < len(self.current):
self.cursor_offset += 1
elif pressed == key.RIGHT:
self.cursor_offset = max(self.cursor_offset - 1, 0)
elif len(pressed) != 1:
return