diff --git a/tngame/cowsay.py b/tngame/cowsay.py new file mode 100644 index 0000000..a74c9bb --- /dev/null +++ b/tngame/cowsay.py @@ -0,0 +1,20 @@ + +def wrap_lines(lines: list[str], max_width: int = 30) -> list[str]: + new_lines = [] + for line in lines: + for line_part in [line[i:i+max_width] for i in range(0, len(line), max_width)]: + new_lines.append(line_part) + return new_lines + + +# Modified from https://github.com/VaasuDevanS/cowsay-python +def generate_bubble(text: str) -> str: + lines = [line.strip() for line in str(text).split("\n")] + lines = wrap_lines([line for line in lines if line]) + text_width = max([len(line) for line in lines]) + output = [] + output.append("." + "=" * (text_width + 2) + ".") + for line in lines: + output.append("| " + line + " " * (text_width - len(line) + 1) + "|") + output.append("'" + "=" * (text_width + 2) + "'") + return '\n'.join(output) diff --git a/tngame/telnet.py b/tngame/telnet.py index dfe3fd1..b4c8161 100644 --- a/tngame/telnet.py +++ b/tngame/telnet.py @@ -8,6 +8,7 @@ import telnetlib3 from hyfetch.color_util import RGB from telnetlib3 import TelnetReaderUnicode, TelnetWriterUnicode +from .cowsay import generate_bubble from .utils import setup_logger, get_ascii_dimensions DEBUG = bool(os.environ.get("DEBUG", False)) @@ -195,6 +196,7 @@ async def shell(reader: TelnetReaderUnicode, writer: TelnetWriterUnicode): def draw_cat(): print_ascii(ASC_CAT, x, y, RGB.from_hex('#ffe797')) + print_ascii(generate_bubble('I hope I can sleep\n on the tree'), x + 6, y - 3, RGB.from_hex('#ffe797')) # Move the cat along the x-axis async def move(delta: int):