diff --git a/npytabletracker/cmd.py b/npytabletracker/cmd.py new file mode 100644 index 0000000..b73c7e4 --- /dev/null +++ b/npytabletracker/cmd.py @@ -0,0 +1,29 @@ +"""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() diff --git a/npytabletracker/data.py b/npytabletracker/data.py new file mode 100644 index 0000000..ec99e98 --- /dev/null +++ b/npytabletracker/data.py @@ -0,0 +1,9 @@ +"""Maintain state in an object for use as a DATA_CONTROLLER.""" + + +class TableState(object): + """Track character initiative, hit points, etc.""" + + def __init__(self): + """Initialize data.""" + self.characters = [] diff --git a/npytabletracker/ui.py b/npytabletracker/ui.py index 20a5e9f..e68e301 100644 --- a/npytabletracker/ui.py +++ b/npytabletracker/ui.py @@ -1,6 +1,12 @@ """UI elements for the npytabletracker application.""" import npyscreen +from npytabletracker.cmd import ManagementActionController +from npytabletracker.data import TableState + + class TableTrackerDisplay(npyscreen.FormMuttActiveTraditional): """Create the high level form, which is organized like mutt/irssi.""" - pass + + ACTION_CONTROLLER = ManagementActionController + DATA_CONTROLER = TableState