import os from time import sleep from typing import Dict from colors import Colors class Layer: def __init__(self, x, y): self.screen = {} self.x = x self.y = y def clear(self): self.screen = {} def put_char(self, char, x, y, *colors): if x > self.x or x < 0 or y > self.y or y < 0: raise ValueError("unexcepted value") self.screen[(x, y)] = "".join(colors) + char + Colors.RESET def put_string(self, string, x, y, *colors): if x > self.x or x < 0 or y > self.y or y < 0: raise ValueError("unexcepted value") line_y = 0 for line in string.split("\n"): for char_x in range(len(line)): self.screen[(x+char_x, y+line_y)] = "".join(colors) + line[char_x] + Colors.RESET line_y += 1 class CLI: def __init__(self): size = os.get_terminal_size() self.x = size[1] - 2 #hauteur self.y = size[0] #largeur self.screen = {} self.__layers = {} def set_layer(self, name: str, layer: Layer): self.__layers[name] = layer def get_layer(self, name: str) -> Layer: return self.__layers[name] def get_layers(self) -> Dict[str, Layer]: return self.__layers 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" #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) cli = CLI() 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)