implement /title and /add commands

this is still just a basic POC step for learning the library, but it
works, now just to understand some stuff
This commit is contained in:
Brian S. Stephan 2020-02-08 19:31:38 -06:00
parent 2a431f509f
commit d8462e6941
3 changed files with 45 additions and 1 deletions

29
npytabletracker/cmd.py Normal file
View File

@ -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()

9
npytabletracker/data.py Normal file
View File

@ -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 = []

View File

@ -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