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