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

View File

@@ -3,6 +3,7 @@ import textwrap
from typing import Any, MutableMapping, List, Match, Optional, Sequence, Union
from agame.action import Action
from agame.color import colorize
from agame.display import Display
from agame.item import Item, ItemInst
from agame.room import Room
from agame.trigger import *
@@ -67,6 +68,8 @@ class Database:
@dataclasses.dataclass
class Game:
# Game display.
display: Display
# Game room/items database
database: Database
# Current room.
@@ -138,13 +141,14 @@ class Game:
"Format, colorize, wrap, and print the message."
if lines:
head = textwrap.fill(lines[0])
print(colorize(head))
# TODO - move colorize to Display
self.display.line(colorize(head))
for line in lines[1:]:
message = textwrap.fill(line)
print()
print(colorize(message))
self.display.line()
self.display.line(colorize(message))
else:
print()
self.display.line()
@property
def rooms(self):