30 lines
1.0 KiB
Python
30 lines
1.0 KiB
Python
"""ActionController for command processing."""
|
|
import re
|
|
|
|
import npyscreen
|
|
|
|
|
|
class ManagementActionController(npyscreen.ActionControllerSimple):
|
|
"""Process commands from the command line and act on them."""
|
|
|
|
ADD_REGEX = r'^/add (.*)$'
|
|
TITLE_REGEX = r'^/title (.*)$'
|
|
|
|
def create(self):
|
|
"""Hook command handlers."""
|
|
self.add_action(self.ADD_REGEX, self.add_character, False)
|
|
self.add_action(self.TITLE_REGEX, self.title, False)
|
|
|
|
def add_character(self, command_line, widget_proxy, live):
|
|
"""Add a character to the list."""
|
|
match = re.search(self.ADD_REGEX, command_line, re.IGNORECASE)
|
|
self.parent.value.characters.append(match.group(1))
|
|
self.parent.wMain.values = self.parent.value.characters
|
|
self.parent.wMain.display()
|
|
|
|
def title(self, command_line, widget_proxy, live):
|
|
"""Set the title in the top status bar."""
|
|
match = re.search(self.TITLE_REGEX, command_line, re.IGNORECASE)
|
|
self.parent.wStatus1.value = match.group(1)
|
|
self.parent.wStatus1.display()
|