如何轻松打印ascii艺术文字? [英] How to easily print ascii-art text?
本文介绍了如何轻松打印ascii艺术文字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个程序可以转储很多输出,并且我希望其中的一些输出真正突出.一种方法可以是用ascii艺术效果渲染重要文本,例如此网络服务例如:
I have a program that dumps a lot of output, and I want some of that output to really stand out. One way could be to render important text with ascii art, like this web service does for example:
# # ## ##### # # # # # ####
# # # # # # ## # # ## # # #
# # # # # # # # # # # # # #
# ## # ###### ##### # # # # # # # # ###
## ## # # # # # ## # # ## # #
# # # # # # # # # # # ####
其他解决方案可以使用彩色或粗体显示.那么如何在Python中轻松地完成这类工作呢?
other solutions could be colored or bold output. So how to do this sort of stuff easily in Python?
推荐答案
-
pyfiglet- http://www.figlet.org
pip install pyfiglet
-
termcolor-ANSI颜色格式的辅助功能
termcolor - helper functions for ANSI color formatting
pip install termcolor
-
colorama-多平台支持(Windows)
colorama - multiplatform support (Windows)
pip install colorama
import sys
from colorama import init
init(strip=not sys.stdout.isatty()) # strip colors if stdout is redirected
from termcolor import cprint
from pyfiglet import figlet_format
cprint(figlet_format('missile!', font='starwars'),
'yellow', 'on_red', attrs=['bold'])
示例
$ python print-warning.py
$ python print-warning.py | cat
.___ ___. __ _______. _______. __ __ _______ __
| \/ | | | / | / || | | | | ____|| |
| \ / | | | | (----` | (----`| | | | | |__ | |
| |\/| | | | \ \ \ \ | | | | | __| | |
| | | | | | .----) | .----) | | | | `----.| |____ |__|
|__| |__| |__| |_______/ |_______/ |__| |_______||_______|(__)
这篇关于如何轻松打印ascii艺术文字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文