Move colorization to the display layer

Color output isn't necessarily always going to be a terminal output
thing, and terminals don't always support the same escape codes (e.g. on
Windows). Thus, all colorization efforts are done in the Display rather
than in the Game.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2021-11-28 17:37:37 -08:00
parent 2357757b23
commit c71077a8f3
4 changed files with 43 additions and 46 deletions

View File

@@ -2,7 +2,6 @@ import dataclasses
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
@@ -141,12 +140,11 @@ class Game:
"Format, colorize, wrap, and print the message."
if lines:
head = textwrap.fill(lines[0])
# TODO - move colorize to Display
self.display.line(colorize(head))
self.display.line(head)
for line in lines[1:]:
message = textwrap.fill(line)
self.display.line()
self.display.line(colorize(message))
self.display.line(message)
else:
self.display.line()