import platform
if 'Windows' in platform.system():
import sys
import ctypes
__stdInputHandle = -10
__stdOutputHandle = -11
__stdErrorHandle = -12
__foreGroundBLUE = 0x09
__foreGroundGREEN = 0x0a
__foreGroundRED = 0x0c
__foreGroundYELLOW = 0x0e
stdOutHandle=ctypes.windll.kernel32.GetStdHandle(__stdOutputHandle)
def setCmdColor(color,handle=stdOutHandle):
return ctypes.windll.kernel32.SetConsoleTextAttribute(handle, color)
def resetCmdColor():
setCmdColor(__foreGroundRED | __foreGroundGREEN | __foreGroundBLUE)
def printBlue(msg):
setCmdColor(__foreGroundBLUE)
sys.stdout.write(msg + '\n')
resetCmdColor()
def printGreen(msg):
setCmdColor(__foreGroundGREEN)
sys.stdout.write(msg + '\n')
resetCmdColor()
def printRed(msg):
setCmdColor(__foreGroundRED)
sys.stdout.write(msg + '\n')
resetCmdColor()
def printYellow(msg):
setCmdColor(__foreGroundYELLOW)
sys.stdout.write(msg + '\n')
resetCmdColor()
else:
STYLE = {
'fore':{
'red': 31,
'green': 32,
'yellow': 33,
'blue': 34,
}
}
def UseStyle(msg, mode = '', fore = '', back = '40'):
fore = '%s' % STYLE['fore'][fore] if STYLE['fore'].has_key(fore) else ''
style = ';'.join([s for s in [mode, fore, back] if s])
style = '\033[%sm' % style if style else ''
end = '\033[%sm' % 0 if style else ''
return '%s%s%s' % (style, msg, end)
def printRed(msg):
print UseStyle(msg,fore='red')
def printGreen(msg):
print UseStyle(msg,fore='green')
def printYellow(msg):
print UseStyle(msg,fore='yellow')
def printBlue(msg):
print UseStyle(msg,fore='blue')
C:\luan\lu4n.com-sqli>python
Python 2.7 (r27:82525, Jul 4 2010, 09:01:59) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> from color import *
>>> printRed('Red')
Red
>>> printGreen('Green')
Green
>>> printYellow('Yellow')
Yellow
>>> printBlue('Blue')
Blue
>>> print 'http://lu4n.com/'
http://lu4n.com/
>>>
[root@Luan ~]# nano test_color.py
[root@Luan ~]# python
Python 2.7.5 (default, Jun 17 2014, 18:11:42)
[GCC 4.8.2 20140120 (Red Hat 4.8.2-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from test_color import *
>>> printRed('Red')
Red
>>> printGreen('Green')
Green
>>>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有