cowyeet_terminal/tengine/main.py

53 lines
1.7 KiB
Python
Raw Normal View History

#!/bin/python3
from os import get_terminal_size
2024-01-14 22:36:39 +01:00
tx,ty = get_terminal_size().columns ,get_terminal_size().lines-2
2024-01-17 19:15:14 +01:00
def clear():
print('\033c', end='')
2024-01-15 20:38:06 +01:00
class tengine():
def __init__(self) -> None:
self.screen = [[' ' for _ in range(tx)] for _ in range(ty+2)]
def print(self):
print(self.strscreen(),end="\r")
def bg_char(self, char=' '):
for a in range(len(self.screen)):
for b in range(len(self.screen[0])):
self.screen[a][b] = char
def strscreen(self):
back = ""
for a in self.screen:
line = ""
for b in a:
line += str(b)
back += line[:tx] + "\n"
return back.lstrip('\n').rstrip('\n')
def set_char(self, character, position):
self.screen[position[0]][position[1]] = character
def set_block(self, block, position):
position = [position[0]+1,position[1]]
pposition = position
for zeichen in block:
if zeichen == '\n':
pposition = [pposition[0] + 1, position[1]]
else:
pposition = [pposition[0], pposition[1] + 1]
self.screen[pposition[0]][pposition[1]] = zeichen
2024-01-17 19:15:14 +01:00
2024-01-15 20:38:06 +01:00
def draw_border(self, border_char='+'):
for i in range(len(self.screen)):
self.screen[i][0] = self.screen[i][-1] = border_char
for j in range(len(self.screen[0])):
self.screen[0][j] = self.screen[-1][j] = border_char
def viereck(self, start_pos, width, height, fill_char='#'):
for i in range(height):
for j in range(width):
self.screen[start_pos[0]+1 + i][start_pos[1] + j] = fill_char