轻松构建ANSI颜色编码字符串。
prettystring的Python项目详细描述
安装
使用pip:
安装pip install prettystring
用法
尽可能直截了当地想:
>>> from prettystring import prettystring as pstr >>> colorful = pstr('sweet!') >>> colorful.__str__() '\x1b[;39;49msweet!\x1b[0m'
prettyStrings使用默认的ANSI代码值初始化。sweet!应该是 默认颜色。用paint():
>>> colorful.paint(pstr.blue) >>> colorful.__str__() '\x1b[;34;49msweet!\x1b[0m' >>> print colorful sweet!
当对其调用print时,colorful的值将显示为蓝色。
您还可以使用以下样式初始化prettyStrings:
>>> stylish = pstr('the answer is 42', pstr.blink, pstr.green, pstr.bgblue) >>> stylish.__str__() '\x1b[5;32;44mthe answer is 42\x1b[0m' >>> print stylish the answer is 42
您甚至可以格式化:
>>> pstr('Hello {}!').paint(pstr.red).format(pstr('world').paint(pstr.blue)) '\x1b[;31;49mHello \x1b[;34;49mworld\x1b[0m\x1b[;31;49m!\x1b[0m'
请注意,该格式返回常规字符串。这是一个已知的限制,并且 正在工作。
prettyString枚举
使用这些枚举值和paint()方法来应用颜色和格式 漂亮的字符串。
请注意,您只能在 一段时间(没有混合颜色(尚未))。
样式(格式)
prettystring.styledefault prettystring.bold prettystring.dim prettystring.underline prettystring.blink prettystring.invert prettystring.hidden
颜色
prettystring.default prettystring.black prettystring.red prettystring.green prettystring.yellow prettystring.blue prettystring.magenta prettystring.cyan prettystring.light prettystring.dark
浅色
prettystring.lred prettystring.lgreen prettystring.lyellow prettystring.lblue prettystring.lmagenta prettystring.lcyan prettystring.white
背景色
prettystring.bgdefault prettystring.bgblack prettystring.bgred prettystring.bggreen prettystring.bgyellow prettystring.bgblue prettystring.bgmagenta prettystring.bgcyan prettystring.bglight prettystring.bgdark
浅色背景色
prettystring.bglred prettystring.bglgreen prettystring.bglyellow prettystring.bglblue prettystring.bglmagenta prettystring.bglcyan prettystring.bgwhite
兼容性
prettyString肯定能在大多数基于Unix的环境中工作。官方的 兼容性测试/升级即将到来。
贡献
提交pull请求可以让prettyString变得更好。我会的 请尽快审阅您的提交。
许可证
这个软件是在麻省理工学院的许可下发布的。有关详细信息,请参见license.md。