Add display abstraction

In case we want to run this on something that isn't an ANSI terminal, we
have the option to implement it however we want.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2021-11-20 19:38:06 -08:00
parent 4cf3608f71
commit e868d0e14f
8 changed files with 202 additions and 35 deletions

32
agame/display/display.py Normal file
View File

@@ -0,0 +1,32 @@
import abc
from typing import Optional
class Display(metaclass=abc.ABCMeta):
"""
Displays are an abstraction over printing things to the screen.
Use a specific implementation based on the kind of display you want to use.
"""
@abc.abstractmethod
def line(self, line: str = ""):
"Print a single line to the display."
@abc.abstractmethod
def input(self) -> str:
"Get player input."
@abc.abstractmethod
def wait_for_ack(self, prompt: Optional[str] = None):
"""
Wait for the user to press a key.
The behavior is up to the implementor. This could be something like
"press any key to continue", "press enter to continue", or "click OK to
continue". This method should block until input is acknowleged by the
user.
"""
def finish(self):
"Final cleanup code for this display."