大量使用带有pyfiglet集成的ansi转义序列的打印实用程序集合

printtools的Python项目详细描述


打印

Print It!

重载python的print函数以添加新的令人兴奋的功能。

依赖关系

  • python3(python2不允许print语句重载)
  • Pyfiglet(阿西艺术,有人吗?)

安装

使用安装

pip install printtools

对于最新版本,请克隆此存储库并使用

python3 setup.py install

用法

首先,import *从print访问所有常量。然后,调用print语句。第一个参数是要打印的对象;所有其他参数都被视为修饰符。例如:

>>> from print import *
>>> print("You can print normally")
You can print normally
>>> print(12345678)
12345678
>>> print("or with ASCII art", SM)
                  _ _   _        _   ___  ___ ___ ___            _
 ___ _ _  __ __ _(_) |_| |_     /_\ / __|/ __|_ _|_ _|  __ _ _ _| |_
/ _ \ '_| \ V  V / |  _| ' \   / _ \\__ \ (__ | | | |  / _` | '_|  _|
\___/_|    \_/\_/|_|\__|_||_| /_/ \_\___/\___|___|___| \__,_|_|  \__|

>>> print("you can combine attributes", RED, BLUE+BG, BOLD)
you can combine attributes

<this will be bold red on a blue background on supported systems>

日志记录

Print带有内置日志记录。使用set_log设置所需的文件,并将追加行:

fromprintimport*set_log('log.txt')print('asdf')# is appended to log.txtprint('Test',SLANT)# is also appended to log.txt as ASCII artprint('Red',RED)# ANSI escape sequences not written

若要禁用日志记录,请使用set_log()set_log(None)set_log设置为“无”。

分隔器

div模块可用于创建美观的分隔符:

>>> div.div('-')
----------------------------------------- # stretches all the way across the terminal
>>> div.div('*', 'Example')
** Example ******************************
>>> div.div('= =', 'Example')
=========================================

                Example

=========================================

图案包括:

  • 单个字符:在屏幕上重复该字符。如果提供了消息,则显示两个字符,后跟空格、消息、空格,然后是占据屏幕其余部分的字符
  • 字符重复,中间有空格:使用该字符在屏幕上绘制两条水平线;在这两条线之间,标签文本在中心绘制。等于空格数的空行将添加到标签文本的顶部和下方。

表格

使用table模块打印表。表格由二维数组组成:

>>> from print import *
>>> t = [["Entry 1", 0.0001, "Value 1"], ["Entry 2", 12345, "Value 2"]]
>>> table.table(t)
+-------+------+-------+
|Entry 1|0.0001|Value 1|
+-------+------+-------+
|Entry 2|12345 |Value 2|
+-------+------+-------+

table.renderrender可以组合起来添加格式:

>>> from print import *
>>> t = [
	[render("Entry 1", RED), 0.0001, "Value 1"],
	[render("Entry 2", GREEN), 12345, "Value 2"]]
>>> print(table.render(t), BOLD)

自定义异常

使用RenderedException类提供更丰富多彩的基本异常类。

>>> class YouFuckedUpError(RenderedException):
...    pass
...
>>> raise YouFuckedUpError("You've really fucked it up this time. Yeah you.")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
__main__.YouFuckedUpError:
__   __        ___        _          _ _   _      ___
\ \ / /__ _  _| __|  _ __| |_____ __| | | | |_ __| __|_ _ _ _ ___ _ _
 \ V / _ \ || | _| || / _| / / -_) _` | |_| | '_ \ _|| '_| '_/ _ \ '_|
  |_|\___/\_,_|_| \_,_\__|_\_\___\__,_|\___/| .__/___|_| |_| \___/_|
                                            |_|
You've really fucked it up this time. Yeah you.

常数

所有常量都可以通过from print import *或通过调用print.<CONST>访问。

基本格式

RESET=0BOLD=1FAINT=2ITALIC=3UNDERLINE=4REVERSE=7CONCEAL=8STRIKEOUT=9

颜色

BLACK=30RED=31GREEN=32YELLOW=33BLUE=34MAGENTA=35CYAN=36WHITE=37

修饰语

BRIGHT=60BR=60BACKGROUND=10BG=10
  • BRIGHT/BR:使用较亮的颜色(并非所有终端都提供;您的里程可能会有所不同)
  • BACKGROUND/BG:设置背景色而不是文本颜色

字体

只有这些字体包含为常量。其他figlet字体(参见figlet的website)可以作为字符串参数传递。

# Standard fontsSM="small"STD="standard"BIG="big"# Isometric fontsISO1="isometric1"ISO2="isometric2"ISO3="isometric3"ISO4="isometric4"# Other fontsSA="contessa"DOOM="doom"DP="drpepper"L3D="larry3d"SMISO="smisome1"KB="smkeyboard"SLANT="slant"SMSLANT="smslant"

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

推荐PyPI第三方库


热门话题
java使用ContentExchange设置请求属性   java Spark/Hdfs/Hdfsclient兼容性   java springcloudstreamkafka配置:instanceCount和instanceIndex   Java中web服务序列化日期   java用动态数据替换占位符   java git gc似乎覆盖了一个packfile,留下了一个打开的文件描述符,其中包含对“oldxxx.pack”的引用   为什么Apache项目对Java版本敏感?   java Anylogic帮助如何在导入的3dobject通过输送机上的多个“站”时更改其颜色?   JavaEclipseNeonM2E可以导入一个大型项目,但似乎不能自动解决依赖关系   java@FindBy搜索具有满足条件的子元素的元素   java如何将ActionEvent e与键绑定一起使用?   java转换以集中方式从外部库抛出的异常   java中用户文件/数据文件与系统/程序文件的区别   java使用变量字符串或字符作为对象名   字体使用Java图形操纵字符串中每个字符的形状   JavaFX图表移动数据   java RandomAccessFile:将所有项设置为相同的字节数?   java Google Play inapp Billing onPurchasesUpdated()错误响应代码1   java在不知道属性名和属性数的情况下处理json对象   java是否可以一次从HazelcastInstance(映射和列表)中删除所有数据?