Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Roblox
GitHub Repository: Roblox/luau
Path: blob/master/bench/color.py
2723 views
1
# This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
2
from enum import Enum
3
import sys
4
5
class Color(Enum):
6
DEFAULT = 0
7
RED = 1
8
GREEN = 2
9
BLUE = 3
10
YELLOW = 4
11
WHITE = 5
12
13
def colored_on(color:Color, message:str):
14
from colorama import Fore, Style
15
color_mappings = {
16
Color.DEFAULT: (Fore.WHITE, Style.NORMAL),
17
Color.RED: (Fore.RED, Style.NORMAL),
18
Color.GREEN: (Fore.GREEN, Style.NORMAL),
19
Color.BLUE: (Fore.BLUE, Style.BRIGHT),
20
Color.YELLOW: (Fore.YELLOW, Style.NORMAL),
21
Color.WHITE: (Fore.WHITE, Style.BRIGHT)
22
}
23
fore, style = color_mappings[color]
24
return fore + style + message + Style.RESET_ALL
25
26
def colored_off(color:Color, message:str):
27
return message
28
29
try:
30
if sys.stdout.isatty():
31
import colorama
32
colorama.init()
33
colored = colored_on
34
else:
35
colored = colored_off
36
except:
37
colored = colored_off
38
39