Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
14-liner: The Momento Storing Class Have Shown Cool Efforts solution in Clear category for Text Editor by Stensen
class Memento:
def __init__(self, text, font): self.text, self.font = text, font
class Text:
def __init__(self): self.text = self.font = ''
def write(self, text): self.text += text
def set_font(self, font): self.font = f'[{font}]'
def restore(self, state): self.text, self.font = state.text, state.font
set_state: Memento = lambda self: Memento(self.text, self.font)
output = lambda self: f'{self.font}{self.text}{self.font}'
show = lambda self: self.output()
class SavedText:
def __init__(self): self._versions = []
def save_text(self, text): self._versions.append(text.set_state())
get_version = lambda self, number: self._versions[number]
Oct. 14, 2020