-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfont.py
More file actions
executable file
·165 lines (145 loc) · 5.07 KB
/
Copy pathfont.py
File metadata and controls
executable file
·165 lines (145 loc) · 5.07 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/usr/bin/python
# -*- coding:utf-8
import os
import sys
import string
try:
import terminal
except:
print('检测出您未安装terminal模块,将替您安装此模块,请稍候……')
os.system('pip install terminal')
import terminal
try:
import console
except:
print('检测出您未安装console模块,将替您安装此模块,请稍候……')
os.system('pip install console')
import console
def red(text):
return terminal.bold(terminal.red(text))
def green(text):
return terminal.green(text)
def blue(text):
return terminal.bold(terminal.blue(text))
def magenta(text):
return terminal.magenta(text)
def yellow(text):
return terminal.yellow(text)
def cyan(text):
return terminal.cyan(text)
def bold(text):#高亮
return terminal.bold(text)
def Processing():
return terminal.magenta(r"[Processing] ")
def Information():
return terminal.cyan(r"[Information] ")
def Detected():
return terminal.bold(terminal.blue(r"[Detected] "))
def Result():
return terminal.bold(terminal.green(r"[Result] "))
def Error():
return terminal.bold(terminal.red(r"[Error] "))
def Input(*num):
if(num and num[0]!= 1):
data = r"<Potato>- "
else:
data = r"<Potato>$ "
return terminal.bold(terminal.yellow(data))
#实现回车换行,而不是结束
def Input_lines(showHead=True):
result = ""
num = 0
while True:
num = num + 1
data = str(input(Input(num))) if showHead else str(input())
if data == '':
if(num==1):
print(Error()+'首行不能为空,请重新输入!\n')
result = ""
num = 0
continue
return result
result+= data+"\n"#换行
#格式化输出
def printF(strData, lenMax, placeHolder=" ", justify="center"):
strData = str(strData)
lenChina = 0
for i in strData:
lenChina+=1 if i not in string.printable else 0
return strData.center(lenMax-lenChina,placeHolder) if justify=="center" else strData.ljust(lenMax-lenChina,placeHolder) if justify=="left" else strData.rjust(lenMax-lenChina,placeHolder)
#调用直接打印table
# printT( [8,13,13,10] ,"top")
# printT( [["ip",8],["域名",13,"left"],["权重",13,"center"],["编号",10]])
# printT( [8,13,13,10] ,"middle")
# printT( [["ip",8],["域名",13,"left"],["权重",13],["编号",10]],type="body")
# printT( [8,13,13,10] ,"bottom")
#tableStyle、fontStyle 分别控制字体和表格颜色
def printT(dataList,type="body",getStr=False,tableStyle="red",fontStyle=""):
def table(str):
if tableStyle == "red":
return red(str)
elif tableStyle == "green":
return green(str)
elif tableStyle == "magenta":
return magenta(str)
elif tableStyle == "blue":
return blue(str)
elif tableStyle == "yellow":
return yellow(str)
elif tableStyle == "cyan":
return cyan(str)
elif tableStyle == "bold":
return bold(str)
else:
return str
def font(str):
if fontStyle == "red":
return red(str)
elif fontStyle == "green":
return green(str)
elif fontStyle == "magenta":
return magenta(str)
elif fontStyle == "blue":
return blue(str)
elif fontStyle == "yellow":
return yellow(str)
elif fontStyle == "cyan":
return cyan(str)
elif fontStyle == "bold":
return bold(str)
else:
return str
try:
str=""
if type == "top":
str = table("┌")
for index, data in enumerate(dataList):
str += table("─" * data)
str += table("┬") if index != len(dataList)-1 else table("┐")
elif type == "bottom":
str = table("└")
for index, data in enumerate(dataList):
str += table("─" * data)
str += table("┴") if index != len(dataList)-1 else table("┘")
elif type == "middle":
str = table("├")
for index, data in enumerate(dataList):
str += table("─" * data)
str += table("┼") if index != len(dataList)-1 else table("┤")
else:
str = table("│")
for data in dataList:
justify = "center" if len(data)==2 else data[2]
str += f"{font(printF(data[0], data[1], justify=justify))}{table('│')}"
if getStr:
return str
else:
print(str)
except Exception as e:
print(f"\033[31m[Error] {e}\r\n")
print('正确使用方法:')
print(' printT( [8,13,13,10] ,"top")')
print(' printT( [["ip",8],["域名",13,"left"],["权重",13],["编号",10]])')
print(' printT( [8,13,13,10] ,"middle")')
print(' printT( [["ip",8],["域名",13,"left"],["权重",13],["编号",10]])')
print(' printT( [8,13,13,10] ,"bottom")\033[0m')