项目作者: 0382

项目描述 :
set console color with python
高级语言: C++
项目地址: git://github.com/0382/color.git
创建时间: 2019-03-09T12:56:02Z
项目社区:https://github.com/0382/color

开源协议:

下载


set console color with python

about this package

I want to have a very easy way to print colorful text in console. In this package, use can use string color name like color="red" to set the output text as red. However, as you know, parsing string is not an easy work. So, this package is not the fastest way to set console color.

about color name

I want to make this package can be used with the same color name in both Windows and Linux. So, the color name of ANSI code follows the wikipedia. However, it is different with Windows API, you can use command color/? to see Windows’ color name. At last, both name are supported in this package.

For bright red, you should use color="bred", and light red (Windows’ name) is "lred".

For background and foreground color, use one char of ";:,\. \t" to split. (You can add split char in the source files before compile, if you like.) For example, "blue;red" means blue background and red foreground.

install

  1. git clone https://github.com/0382/color.git
  2. cd color
  3. python setup.py install --record installed.txt

usgae

  • example
  1. import color
  2. @color.color('red')
  3. def myprint(*args, **kw):
  4. print(*args)
  5. for k, v in kw.items():
  6. if(k == 'poor_man'):
  7. color.printc(f'{k}: {v}', color='bcyan;yellow')
  8. elif(k == 'python'):
  9. color.printc(f'{k}: {v}', color='23;160;250') # rgb can not work on windows
  10. else:
  11. color.printc(f'{k}: {v}')
  12. if __name__ == '__main__':
  13. myprint('hello,',' world', poor_man = 'I like python', what = 'the fuck', python = 'I love c++')