Colorful独立
This commit is contained in:
@@ -5,35 +5,112 @@ import sys
|
|||||||
import threading
|
import threading
|
||||||
import traceback
|
import traceback
|
||||||
import datetime
|
import datetime
|
||||||
try:
|
|
||||||
from colorama import Fore as ConsoleFrontColor, Back as ConsoleBackgroundColor, Style as ConsoleStyle
|
# region ansi colorful
|
||||||
except:
|
|
||||||
print("colorama is not installed")
|
# Copyright Jonathan Hartley 2013. BSD 3-Clause license
|
||||||
class ConsoleFrontColor:
|
'''
|
||||||
RED = ""
|
This module generates ANSI character codes to printing colors to terminals.
|
||||||
GREEN = ""
|
See: http://en.wikipedia.org/wiki/ANSI_escape_code
|
||||||
YELLOW = ""
|
'''
|
||||||
BLUE = ""
|
|
||||||
MAGENTA = ""
|
CSI = '\033['
|
||||||
CYAN = ""
|
OSC = '\033]'
|
||||||
WHITE = ""
|
BEL = '\a'
|
||||||
RESET = ""
|
|
||||||
class ConsoleBackgroundColor:
|
|
||||||
RED = ""
|
def code_to_chars(code):
|
||||||
GREEN = ""
|
return CSI + str(code) + 'm'
|
||||||
YELLOW = ""
|
|
||||||
BLUE = ""
|
def set_title(title):
|
||||||
MAGENTA = ""
|
return OSC + '2;' + title + BEL
|
||||||
CYAN = ""
|
|
||||||
WHITE = ""
|
def clear_screen(mode=2):
|
||||||
RESET = ""
|
return CSI + str(mode) + 'J'
|
||||||
class ConsoleStyle:
|
|
||||||
RESET = ""
|
def clear_line(mode=2):
|
||||||
BOLD = ""
|
return CSI + str(mode) + 'K'
|
||||||
DIM = ""
|
|
||||||
UNDERLINE = ""
|
|
||||||
REVERSE = ""
|
class AnsiCodes(object):
|
||||||
HIDDEN = ""
|
def __init__(self):
|
||||||
|
# the subclasses declare class attributes which are numbers.
|
||||||
|
# Upon instantiation we define instance attributes, which are the same
|
||||||
|
# as the class attributes but wrapped with the ANSI escape sequence
|
||||||
|
for name in dir(self):
|
||||||
|
if not name.startswith('_'):
|
||||||
|
value = getattr(self, name)
|
||||||
|
setattr(self, name, code_to_chars(value))
|
||||||
|
|
||||||
|
|
||||||
|
class ConsoleCursor(object):
|
||||||
|
def UP(self, n=1):
|
||||||
|
return CSI + str(n) + 'A'
|
||||||
|
def DOWN(self, n=1):
|
||||||
|
return CSI + str(n) + 'B'
|
||||||
|
def FORWARD(self, n=1):
|
||||||
|
return CSI + str(n) + 'C'
|
||||||
|
def BACK(self, n=1):
|
||||||
|
return CSI + str(n) + 'D'
|
||||||
|
def POS(self, x=1, y=1):
|
||||||
|
return CSI + str(y) + ';' + str(x) + 'H'
|
||||||
|
|
||||||
|
|
||||||
|
class ConsoleFrontColorClass(AnsiCodes):
|
||||||
|
BLACK = 30
|
||||||
|
RED = 31
|
||||||
|
GREEN = 32
|
||||||
|
YELLOW = 33
|
||||||
|
BLUE = 34
|
||||||
|
MAGENTA = 35
|
||||||
|
CYAN = 36
|
||||||
|
WHITE = 37
|
||||||
|
RESET = 39
|
||||||
|
|
||||||
|
# These are fairly well supported, but not part of the standard.
|
||||||
|
LIGHTBLACK_EX = 90
|
||||||
|
LIGHTRED_EX = 91
|
||||||
|
LIGHTGREEN_EX = 92
|
||||||
|
LIGHTYELLOW_EX = 93
|
||||||
|
LIGHTBLUE_EX = 94
|
||||||
|
LIGHTMAGENTA_EX = 95
|
||||||
|
LIGHTCYAN_EX = 96
|
||||||
|
LIGHTWHITE_EX = 97
|
||||||
|
|
||||||
|
ConsoleFrontColor = ConsoleFrontColorClass()
|
||||||
|
|
||||||
|
class ConsoleBackgroundColorClass(AnsiCodes):
|
||||||
|
BLACK = 40
|
||||||
|
RED = 41
|
||||||
|
GREEN = 42
|
||||||
|
YELLOW = 43
|
||||||
|
BLUE = 44
|
||||||
|
MAGENTA = 45
|
||||||
|
CYAN = 46
|
||||||
|
WHITE = 47
|
||||||
|
RESET = 49
|
||||||
|
|
||||||
|
# These are fairly well supported, but not part of the standard.
|
||||||
|
LIGHTBLACK_EX = 100
|
||||||
|
LIGHTRED_EX = 101
|
||||||
|
LIGHTGREEN_EX = 102
|
||||||
|
LIGHTYELLOW_EX = 103
|
||||||
|
LIGHTBLUE_EX = 104
|
||||||
|
LIGHTMAGENTA_EX = 105
|
||||||
|
LIGHTCYAN_EX = 106
|
||||||
|
LIGHTWHITE_EX = 107
|
||||||
|
|
||||||
|
ConsoleBackgroundColor = ConsoleBackgroundColorClass()
|
||||||
|
|
||||||
|
class ConsoleStyleClass(AnsiCodes):
|
||||||
|
BRIGHT = 1
|
||||||
|
DIM = 2
|
||||||
|
NORMAL = 22
|
||||||
|
RESET_ALL = 0
|
||||||
|
|
||||||
|
ConsoleStyle = ConsoleStyleClass()
|
||||||
|
|
||||||
|
# endregion
|
||||||
|
|
||||||
class NotImplementedError(Exception):
|
class NotImplementedError(Exception):
|
||||||
def __init__(self, message:Optional[str]=None) -> None:
|
def __init__(self, message:Optional[str]=None) -> None:
|
||||||
|
@@ -3,8 +3,7 @@ import os
|
|||||||
from time import sleep
|
from time import sleep
|
||||||
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||||
|
|
||||||
from Convention.Runtime.File import *
|
from Convention.Runtime.Config import *
|
||||||
|
|
||||||
file = ToolFile("[Test]")|"temp"|None
|
PrintColorful(ConsoleFrontColor.RED, "Hello, World!")
|
||||||
print(file.MustExistsPath())
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user