From 803c2cfba2a8d6b81c6b2b7837b2a2456b8b8cbb Mon Sep 17 00:00:00 2001 From: Azalea Gui Date: Tue, 7 Mar 2023 23:08:12 -0500 Subject: [PATCH] [+] Get screen size function --- tngame/telnet.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tngame/telnet.py b/tngame/telnet.py index b7c40d8..fce5373 100644 --- a/tngame/telnet.py +++ b/tngame/telnet.py @@ -29,6 +29,17 @@ COLORS = {RGB.from_hex(v) for v in { async def shell(reader: TelnetReaderUnicode, writer: TelnetWriterUnicode): + async def get_size() -> tuple[int, int]: + # Get the size of the terminal + writer.write('\x1b[18t') + await writer.drain() + size = await reader.read(100) + + # Parse the size, it's in the format of \x1b[8;{height};{width}t + height, width = size.split(';')[1:3] + height, width = int(height), int(width[:-1]) + + return height, width def print_ascii(asc: str, x: int, y: int): asc = asc.strip('\n')