def keypress(self, size, key): key = super().keypress(size, key) if key == 'enter': self._on_return(self.get_edit_text()) self.set_edit_text('') elif key not in self._keys.values() and key in readlike.keys(): text, pos = readlike.edit(self.edit_text, self.edit_pos, key) self.set_edit_text(text) self.set_edit_pos(pos) else: return key
def keypress(self, size, key): if key == 'begin paste': self._paste_mode = True elif key == 'end paste': self._paste_mode = False elif key == 'enter' and not self._paste_mode: self._on_return(self.get_edit_text()) self.set_edit_text('') elif key not in self._keys.values() and key in readlike.keys(): text, pos = readlike.edit(self.edit_text, self.edit_pos, key) self.set_edit_text(text) self.set_edit_pos(pos) else: return super().keypress(size, key)
def test_edit(self): self.assertEqual(rl.edit('test', 4, 's'), ('tests', 5)) self.assertEqual(rl.edit('test', 4, 'ctrl h'), ('tes', 3)) self.assertEqual(rl.edit('test', 4, 'bogus'), ('test', 4))