Initial commit with a mostly working engine.
Basic commands are being parsed. I think the only weird part is the 'use' command because it needs to possibly target two things. A tiny test example is provided in __main__, this will probably be broken out later. Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
39
agame/color.py
Normal file
39
agame/color.py
Normal file
@@ -0,0 +1,39 @@
|
||||
import re
|
||||
|
||||
|
||||
__all__ = ("colorize",)
|
||||
|
||||
BOLD_PAT = re.compile(r"\*\*(.+?)\*\*", re.MULTILINE)
|
||||
ITALIC_PAT = re.compile(r"//(.+?)//", re.MULTILINE)
|
||||
INTEREST_PAT = re.compile(r"\(\((.+?)\)\)", re.MULTILINE)
|
||||
SHADOW_PAT = re.compile(r"\{\{(.+?)\}\}", re.MULTILINE)
|
||||
|
||||
BOLD_COL = "\u001b[1m"
|
||||
ITALIC_COL = "\u001b[3m"
|
||||
INTEREST_COL = "\u001b[34;1m"
|
||||
SHADOW_COL = "\u001b[30;1m"
|
||||
RESET_COL = "\u001b[0m"
|
||||
|
||||
|
||||
def colorize(text: str) -> str:
|
||||
"""
|
||||
Colorizes text for output on an ANSI terminal.
|
||||
|
||||
This will use escape codes to replace things.
|
||||
|
||||
Style guide:
|
||||
((This)) is "interest" styling. This will make the text blue.
|
||||
{{This}} is "shadow" styling. This will make the text a dark grey (or at
|
||||
least, more subtle.)
|
||||
"""
|
||||
replacements = [
|
||||
(INTEREST_PAT, INTEREST_COL),
|
||||
(SHADOW_PAT, SHADOW_COL),
|
||||
(BOLD_PAT, BOLD_COL),
|
||||
(ITALIC_PAT, ITALIC_COL),
|
||||
]
|
||||
|
||||
for (pat, col) in replacements:
|
||||
text = pat.sub(col + r"\1" + RESET_COL, text)
|
||||
|
||||
return text
|
||||
Reference in New Issue
Block a user