You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
2.2 KiB

import os
class Colors:
def __init__(self):
""" ANSI color codes """
self.BLACK = "\033[0;30m"
self.RED = "\033[0;31m"
self.GREEN = "\033[0;32m"
self.BROWN = "\033[0;33m"
self.BLUE = "\033[0;34m"
self.PURPLE = "\033[0;35m"
self.CYAN = "\033[0;36m"
self.LIGHT_GRAY = "\033[0;37m"
self.DARK_GRAY = "\033[1;30m"
self.LIGHT_RED = "\033[1;31m"
self.LIGHT_GREEN = "\033[1;32m"
self.YELLOW = "\033[1;33m"
self.LIGHT_BLUE = "\033[1;34m"
self.LIGHT_PURPLE = "\033[1;35m"
self.LIGHT_CYAN = "\033[1;36m"
self.LIGHT_WHITE = "\033[1;37m"
self.BOLD = "\033[1m"
self.FAINT = "\033[2m"
self.ITALIC = "\033[3m"
self.UNDERLINE = "\033[4m"
self.END = "\033[0m"
class Cli(Colors):
"""Classe gérant l'interface graphique"""
def __init__(self, **kwargs):
super().__init__()
self.width = os.get_terminal_size().columns
self.height = os.get_terminal_size().lines -1
for key, value in kwargs.items():
if key == 'width':
self.width = value
elif key == 'height':
self.height = value-1
self.__set_dimensions()
self.screen = [[' ' for i in range(self.width)] for j in range(self.height)]
def __set_dimensions(self):
""" Défini les dimensions du terminal """
os.system('resize -s {} {}'.format(self.height + 1, self.width))
os.system('clear')
def display(self):
"""affiche le contenu de self.screen"""
os.system('clear')
for line in self.screen:
print(''.join(line))
self.screen = [[' ' for i in range(self.width)] for j in range(self.height)]
def draw(self, content, x, y):
"""dessine aux coordonées"""
for i in range(len(str(content))):
try:
if content[i] != ' ':
self.screen[y][x+i] = content[i]
except(IndexError):
break
def draw_life(self, percent, x, y):
"""dessine la barre de vie"""
length = 40
part_to_draw = length * percent // 100
if percent > 25:
self.draw('|{}{}|'.format(''.join(['' for i in range(part_to_draw)]), ''.join([' ' for i in range(length - part_to_draw)])), x, y)
else:
self.draw('{}|{}{}|{}'.format(self.RED, ''.join(['' for i in range(part_to_draw)]), ''.join([' ' for i in range(length - part_to_draw)]), self.END), x, y)