52 lines
1.5 KiB
Python
52 lines
1.5 KiB
Python
#!/bin/python3
|
|
from os import get_terminal_size
|
|
tx,ty = get_terminal_size().columns ,get_terminal_size().lines-2
|
|
|
|
def genfeld():
|
|
return [[' ' for _ in range(tx)] for _ in range(ty+2)]
|
|
|
|
def bg_char(feld, char=' '):
|
|
for a in range(len(feld)):
|
|
for b in range(len(feld[0])):
|
|
feld[a][b] = char
|
|
return feld
|
|
|
|
def strfeld(feld):
|
|
return '\n'.join([''.join(row) for row in feld]).lstrip('\n').rstrip('\n')
|
|
def prfeld(feld):
|
|
print(strfeld(feld),end="\r")
|
|
|
|
def change_char(feld, character, position):
|
|
feld[position[0]][position[1]] = character
|
|
|
|
def change_block(feld, 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]
|
|
feld[pposition[0]][pposition[1]] = zeichen
|
|
return feld
|
|
|
|
def clear():
|
|
print('\033c', end='')
|
|
|
|
def draw_border(feld, border_char='+'):
|
|
for i in range(len(feld)):
|
|
feld[i][0] = feld[i][-1] = border_char
|
|
for j in range(len(feld[0])):
|
|
feld[0][j] = feld[-1][j] = border_char
|
|
global tx,ty
|
|
tx -= 2;ty -= 2
|
|
return feld
|
|
|
|
#def move_cursor(x, y):
|
|
# print(f'\033[{y};{x}H', end='')
|
|
|
|
def viereck(feld, start_pos, width, height, fill_char='#'):
|
|
for i in range(height):
|
|
for j in range(width):
|
|
feld[start_pos[0]+1 + i][start_pos[1] + j] = fill_char
|
|
return feld
|