Browse Source

layer drawing

old
Kalyax 2 years ago
parent
commit
e21f350995
  1. 60
      cli/cli.py

60
cli/cli.py

@ -6,8 +6,8 @@ from colors import Colors
class Layer: class Layer:
def __init__(self, x, y): def __init__(self, x, y):
self.screen = {} self.screen = {}
self.x = x self.x = x #largeur
self.y = y self.y = y #hauteur
def clear(self): def clear(self):
self.screen = {} self.screen = {}
@ -30,8 +30,8 @@ class Layer:
class CLI: class CLI:
def __init__(self): def __init__(self):
size = os.get_terminal_size() size = os.get_terminal_size()
self.x = size[1] - 2 #hauteur self.x = size.columns #largeur
self.y = size[0] #largeur self.y = size.lines - 2 #hauteur
self.screen = {} self.screen = {}
self.__layers = {} self.__layers = {}
@ -44,35 +44,39 @@ class CLI:
def get_layers(self) -> Dict[str, Layer]: def get_layers(self) -> Dict[str, Layer]:
return self.__layers return self.__layers
def __combine_layers(self): def combine_layers(self):
layers = self.get_layers() layers = self.get_layers()
#for layer in layers: self.screen = {}
# for y in range(layer.x): for layer_name in layers:
# for x in range(layer.y): for x in range(layers[layer_name].x):
# if (x, y) in layer.screen: for y in range(layers[layer_name].y):
# content += layer.screen[(x, y)] if (x, y) in layers[layer_name].screen:
# else: self.screen[(x, y)] = layers[layer_name].screen[(x, y)]
# content += " "
# content += "\n"
#def draw(self):
# print("\033[H\033[J", end="")
# content = ""
# for y in range(self.x):
# for x in range(self.y):
# if (x, y) in self.screen:
# content += self.screen[(x, y)]
# else:
# content += " "
# content += "\n"
# print(content)
def draw(self):
cli.combine_layers()
content = ""
for y in range(self.y):
#content += "\n"
for x in range(self.x):
if (x, y) in self.screen:
content += self.screen[(x, y)]
else:
content += "a"
content += "\n"
print("\033[H\033[J", end="")
print(content)
cli = CLI() cli = CLI()
cli.put_char("t", 5, 6, Colors.BLUEBG, Colors.BLACK) layer = Layer(cli.x, cli.y)
cli.put_string("tttaaaaaa ttt \n ttttttttttnnnnnn t", 8, 9, Colors.BEIGEBG) layer.put_char("t", 5, 6, Colors.BLUEBG, Colors.BLACK)
layer.put_string("""test""", 8, 9, Colors.BEIGEBG)
cli.set_layer("test", layer)
##cli.put_char("t", 5, 6, Colors.BLUEBG, Colors.BLACK)
#cli.put_string("tttaaaaaa ttt \n ttttttttttnnnnnn t", 8, 9, Colors.BEIGEBG)
#cli.draw() #cli.draw()
while True: while True:
cli.draw() cli.draw()
sleep(0.1) sleep(1)
Loading…
Cancel
Save