-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathESC2python.py
70 lines (53 loc) · 1.47 KB
/
ESC2python.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import os
def CursorSave():
print("\0337", end="", flush=True)
def CursorRestore():
print("\0338", end="", flush=True)
def CursorDown(y):
print("\x1B[" + str(y) + "B", end="", flush=True)
def CursorRight(x):
print("\x1B[" + str(x) + "C", end="", flush=True)
def CursorLeft(x):
print("\x1B[" + str(x) + "D", end="", flush=True)
def CursorUp(y):
print("\x1B[" + str(y) + "A", end="", flush=True)
def CursorMoveX(x):
if x > 0:
CursorRight(x)
elif x < 0:
CursorLeft(x * -1)
def CursorMoveY(y):
if y > 0:
CursorUp(y)
elif y < 0:
CursorDown(y * -1)
def CursorMoveXY(x, y):
CursorMoveX(x)
CursorMoveY(y)
def CLS():
os.system('cls' if os.name == 'nt' else 'clear')
def TxtBold(set):
if set:
print("\x1B[1m", end="", flush=True)
else:
print("\x1B[22m", end="", flush=True)
def ResetForeGround():
print("\x1B[39m", end="", flush=True)
def ResetBackGround():
print("\x1B[49m", end="", flush=True)
def ResetForeBack():
ResetForeGround()
ResetBackGround()
def SetForeGround(c):
if not ((c > 29 and c < 38) or (c > 89 and c < 98)):
ResetForeGround()
else:
print("\x1B[" + str(c) + "m", end="", flush=True)
def SetBackGround(c):
if not ((c > 39 and c < 48) or (c > 99 and c < 108)):
ResetBackGround()
else:
print("\x1B[" + str(c) + "m", end="", flush=True)
def SetForeBack(fc, bc):
SetForeGround(fc)
SetBackGround(bc)