- def __init__(self, widget1, widget2, message_container):
- self.widget1 = widget1
- self.widget2 = widget2
- self.message_container = message_container
-
- def handle_input(self, trigger):
- """On input from other thread, either quit or write to widget text.
-
- Serves as a receiver to urwid's watch_pipe mechanism, with trigger
- the data that a pipe defined by watch_pipe delivers. To avoid
- buffering trouble, we don't care for that data beyond the fact that
- its receival triggers this function: The sender is to write the
- data it wants to deliver into the container referenced by
- self.message_container, and just pipe the trigger to inform us
- about this.
-
- If the message delivered is 'BYE', quits Urbit.
- """
- if self.message_container[0] == 'BYE':
- raise urwid.ExitMainLoop()
- return
- self.widget1.set_text('SERVER: ' + self.message_container[0])
- self.widget2.set_text('loremipsumdolorsitamet '
- 'loremipsumdolorsitamet'
- 'loremipsumdolorsitamet '
- 'loremipsumdolorsitamet\n'
- 'loremipsumdolorsitamet '
- 'loremipsumdolorsitamet')
+ Serves as a receiver to urwid's watch_pipe mechanism, with trigger the
+ data that a pipe defined by watch_pipe delivers. To avoid buffering
+ trouble, we don't care for that data beyond the fact that its receival
+ triggers this function: The sender is to write the data it wants to
+ deliver into the container referenced by self.server_output, and just
+ pipe the trigger to inform us about this.
+
+ If the message delivered is 'BYE', quits Urwid. Otherwise tries to
+ parse it as a command, and enact it. In all cases but the 'BYE', calls
+ self.widget_manager.update.
+ """
+ msg = self.server_output[0]
+ if msg == 'BYE':
+ raise urwid.ExitMainLoop()
+ try:
+ command = self.parser.parse(msg)
+ if command is None:
+ self.game.log('UNHANDLED INPUT: ' + msg)
+ else:
+ command()
+ except ArgError as e:
+ self.game.log('ARGUMENT ERROR: ' + msg + '\n' + str(e))
+ self.widget_manager.update()
+ del self.server_output[0]