Last active
April 12, 2019 12:35
-
-
Save Sean-Bradley/17e23916488d049e523bedcfd86616e4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def execute(self, command_name, *args): | |
"""Execute a pre defined command and log in history""" | |
if command_name in self._commands.keys(): | |
self._history_position += 1 | |
self._commands[command_name].execute(args) | |
if len(self._history) == self._history_position: | |
# This is a new event in hisory | |
self._history.append((time.time(), command_name, args)) | |
else: | |
# This occurs if there was one of more UNDOs and then a new | |
# execute command happened. In case of UNDO, the history_position | |
# changes, and executing new commands purges any history after | |
# the current position""" | |
self._history = self._history[:self._history_position+1] | |
self._history[self._history_position] = { | |
time.time(): [command_name, args] | |
} | |
else: | |
print(f"Command [{command_name}] not recognised") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment