1 """The `engine` module provides :class:`CommandEngine` for executing
2 :class:`hooke.command.Command`\s.
5 from .ui import CloseEngine, CommandMessage
7 class CommandEngine (object):
8 def run(self, ui_to_command_queue, command_to_ui_queue):
9 """Get a :class:`hooke.ui.QueueMessage` from the incoming
10 `ui_to_command_queue` and act accordingly.
12 If the message is a :class:`hooke.ui.CommandMessage` instance,
13 the command run may read subsequent input from
14 `ui_to_command_queue` (if it is an interactive command). The
15 command may also put assorted data into `command_to_ui_queue`.
17 When the command completes, it will put a
18 :class:`hooke.command.CommandExit` instance into
19 `command_to_ui_queue`, at which point the `CommandEngine` will
20 be ready to receive the next :class:`hooke.ui.QueueMessage`.
23 msg = ui_to_command_queue.get()
24 if isinstance(msg, CloseEngine):
26 assert isinstance(msg, CommandMessage), type(msg)
27 msg.command.run(ui_to_command_queue, command_to_ui_queue,