From e21f350995691e1a06f2745c0e28732d9007c5b8 Mon Sep 17 00:00:00 2001 From: Kalyax Date: Sat, 10 Sep 2022 16:26:55 +0200 Subject: [PATCH] layer drawing --- cli/cli.py | 60 +++++++++++++++++++++++++++++------------------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/cli/cli.py b/cli/cli.py index 49a7bbd..474786b 100644 --- a/cli/cli.py +++ b/cli/cli.py @@ -6,8 +6,8 @@ from colors import Colors class Layer: def __init__(self, x, y): self.screen = {} - self.x = x - self.y = y + self.x = x #largeur + self.y = y #hauteur def clear(self): self.screen = {} @@ -30,8 +30,8 @@ class Layer: class CLI: def __init__(self): size = os.get_terminal_size() - self.x = size[1] - 2 #hauteur - self.y = size[0] #largeur + self.x = size.columns #largeur + self.y = size.lines - 2 #hauteur self.screen = {} self.__layers = {} @@ -44,35 +44,39 @@ class CLI: def get_layers(self) -> Dict[str, Layer]: return self.__layers - def __combine_layers(self): + def combine_layers(self): layers = self.get_layers() - #for layer in layers: - # for y in range(layer.x): - # for x in range(layer.y): - # if (x, y) in layer.screen: - # content += layer.screen[(x, y)] - # else: - # content += " " - # content += "\n" + self.screen = {} + for layer_name in layers: + for x in range(layers[layer_name].x): + for y in range(layers[layer_name].y): + if (x, y) in layers[layer_name].screen: + self.screen[(x, y)] = layers[layer_name].screen[(x, y)] - #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.put_char("t", 5, 6, Colors.BLUEBG, Colors.BLACK) -cli.put_string("tttaaaaaa ttt \n ttttttttttnnnnnn t", 8, 9, Colors.BEIGEBG) +layer = Layer(cli.x, cli.y) +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() while True: cli.draw() - sleep(0.1) \ No newline at end of file + sleep(1) \ No newline at end of file