AnsiColors带来了一种在终端中使用颜色的简单而强大的方法。

ANSIColors-balises的Python项目详细描述


关于

提供efficient和有用的functionshtml标记样式使用颜色。

几乎所有的ANSI颜色都是用这种类似样式的标记定义的。 这一点是本模块的主要兴趣所在, 因为许多其他函数定义了用某些颜色打印的函数。

reset标记是一个特殊的标记,用于重新初始化以前更改的所有参数。

颜色

前场

您可以选择8种基本ANSI颜色之一:黑色、红色、绿色、黄色、蓝色, 洋红,青色,白色。 以lower scriptdesignforeground颜色开头的名称。

例如

ANSIColors.printc('<reset>this is default. <red>this is red<yellow> and yellow in foreground now<reset>').

背景

您可以选择8种基本ANSI颜色之一:黑色、红色、绿色、黄色、蓝色, 洋红,青色,白色。 名称以upper scriptdesignbackground颜色开头。

例如

ANSIColors.printc('<Default>this is default. <Blue>this have a blue background<Black> and black in background now<reset>').

其他标签

还提供以下标签:

  • ^{tt1}$, ^{tt2}$ : to turn on and off the italic mode (not always supported),
  • ^{tt3}$, ^{tt4}$ : to turn on and off the bold mode (not always supported),
  • ^{tt5}$, ^{tt6}$ : to turn on and off the underline mode (not always supported),
  • ^{tt7}$, ^{tt8}$ : to turn on and off the reverse video mode,
  • ^{tt9}$, ^{tt10}$ : to turn on and off the blink mode (not always supported),
  • ^{tt11}$ : to erase the current line,
  • ^{tt12}$ : to make the terminal’s bell ring (not always supported).

还提供了一些宏,如标记<ERROR><INFO><WARNING>

以及<warning><question>,分别给出了一个彩色的!?

写入文件

这可以通过writec函数实现。例如

import sys
ANSIColors.writec('<ERROR><u><red>The computer is going to explode!<reset>', fn=sys.stderr)
# sys.stderr.flush()
# this is useless : writec flush itself.

自动检测

当然,如果输出不支持颜色(例如文件或管道命令),则颜色将被禁用。

它在gnu/linux(在ubuntu、arch-linux、debian、fedora和angstrom上测试)和windows(无论有没有cygwin)上都能完美工作, 让not在mac os x上测试(但应该没问题)。

其他功能

其他功能

此模块还提供xtitle函数,用于更改终端的标题。 它尝试使用命令xtitle,如果不可用,则尝试使用一个ansi code来更改标题。

此模块提供一个notify函数来显示系统通知(在类debian上使用notify-send,而不是在windows上工作)。

脚本

ANSIColors.py也是一个脚本。 您可以直接使用

python -m ANSIColors --help

用于测试

它可以用来运行一些测试(使用–test选项)。

使用gnu/bash

它可以用来生成gnu/bash颜色配置文件 (使用--generate--file color.sh选项)。

这个sh文件可以用$ . color.sh在任何gnu/bash脚本中导入, 甚至在~/.bashrc文件中。

可以找到此完整颜色配置文件的最新版本 on my webpage

许可证

此模块根据gnu public license第3版(gplv3的条款获得许可。 有关详细信息,请参见文件license

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
从FXML转换为JAVA时,不会加载javafx映像   泛型Java模板调用运行时推断   javascript为什么我的活动没有响应我在样式文件中所做的更改?   如何在HttpClient(java、apache)中自动重定向   java CSV到H2字符编码不匹配   在Java中使用BorderLayout按比例调整用户界面大小   Java中的重定向异常   java RecyclerView搜索过滤器仅过滤一个值   java标准api multiselect与count和distinct不起作用   java为什么我在Solr上做的每一个查询都会占用我10s MB的堆内存?   java如何使用方法解决:锁定帐户三次后?   java如何实现睡眠以显示图像的幻灯片   在Java中,按对象参数对映射<对象,列表<对象>>进行排序   java无法从密钥库读取密钥   java试图将水平recycleview嵌套到垂直recycleview中   认识C++对Web应用开发的重要性   使用共享对象实例化多个Runnable的java含义?   javabeans何时使用JavaBean?