惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

月光博客
月光博客
Microsoft Security Blog
Microsoft Security Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 叶小钗
博客园 - 三生石上(FineUI控件)
爱范儿
爱范儿
T
Tailwind CSS Blog
F
Fortinet All Blogs
Blog — PlanetScale
Blog — PlanetScale
WordPress大学
WordPress大学
H
Help Net Security
Apple Machine Learning Research
Apple Machine Learning Research
Y
Y Combinator Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
GbyAI
GbyAI
Martin Fowler
Martin Fowler
有赞技术团队
有赞技术团队
腾讯CDC
V
V2EX
Jina AI
Jina AI
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
B
Blog
M
MIT News - Artificial intelligence
宝玉的分享
宝玉的分享

陈少文的网站

巨变与机遇的未来十年 Kubernetes 平台管理软件压力测试方案 使用镜像部署 Hexo 静态页面 终于等到你 - GitHub 镜像仓库服务(ghcr.io) 一起来学 Go --(6)Interface 一起来学 Go --(5)Goroutine 和 Channel 什么是函数式编程 如何在 Kubernetes 集群集成 Kata 柯里化与偏函数 使用 PyGithub 自动创建 Label 软件产品是团队能力的输出 Helm 2 、Helm 3 比较 IoT 变现 Kubernetes 中的 DNS 服务 国内的 Helm 镜像源 Harbor 使用自签证书支持 Https 访问 DevOps 工具链之 Prow 如何使用 kfctl 安装 Kubeflow VS Code 无法下载 Go 插件的工具包 工程师更应具有服务精神 你不知道的 Docker 使用技巧 使用 Docker 运行 Tensorflow 论中国 什么是左移 如何清空 Git 仓库全部历史记录 一禅小和尚 有风吹过厨房 时间的玫瑰 如何在 CentOS 安装 GPU 驱动 开发 Tips(19)
命令行 Banner 生成工具 - pyfiglet
微信公众号 · 2021-02-04 · via 陈少文的网站

1. 什么是 pyfiglet

pyfiglet 是一个用 Python 实现的 ASCII 艺术字生成工具。可以根据字符生成如下图形:

1
2
3
4
5
6
 _          _ _                             _     _ _
| |__   ___| | | ___    __      _____  _ __| | __| | |
| '_ \ / _ \ | |/ _ \   \ \ /\ / / _ \| '__| |/ _` | |
| | | |  __/ | | (_) |   \ V  V / (_) | |  | | (_| |_|
|_| |_|\___|_|_|\___( )   \_/\_/ \___/|_|  |_|\__,_(_)
                    |/

在编写 CLI 工具时,可以用 pyfiglet 生成 Banner 展示在命令行。

2. 安装

在 Python 环境下,使用 pip 安装:

3. 演示使用

先查看一下帮助文档:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
pyfiglet --help

Usage: pyfiglet [options] [text..]

Options:
  --version             show program's version number and exit
  -h, --help            show this help message and exit
  -f FONT, --font=FONT  font to render with (default: standard)
  -D DIRECTION, --direction=DIRECTION
                        set direction text will be formatted in (default:
                        auto)
  -j SIDE, --justify=SIDE
                        set justification, defaults to print direction
  -w COLS, --width=COLS
                        set terminal width for wrapping/justification
                        (default: 80)
  -r, --reverse         shows mirror image of output text
  -F, --flip            flips rendered output text over
  -l, --list_fonts      show installed fonts list
  -i, --info_font       show font's information, use with -f FONT
  -L LOAD, --load=LOAD  load and install the specified font definition
  -c COLOR, --color=COLOR
                        prints text with passed foreground color,
                        --color=foreground:background
                        --color=:background                  # only background
                        --color=foreground | foreground:     # only foreground
                        --color=list                         # list all colors
                        COLOR = list[COLOR] | [0-255];[0-255];[0-255] (RGB)

下面直接试试这些参数:

  • 默认参数
1
2
3
4
5
6
7
pyfiglet Kube

 _  __     _
| |/ /   _| |__   ___
| ' / | | | '_ \ / _ \
| . \ |_| | |_) |  __/
|_|\_\__,_|_.__/ \___|
  • 居中对齐
1
2
3
4
5
6
pyfiglet Kube -j center
                              _  __     _
                             | |/ /   _| |__   ___
                             | ' / | | | '_ \ / _ \
                             | . \ |_| | |_) |  __/
                             |_|\_\__,_|_.__/ \___|
  • 指定字体

字体可以在 http://www.figlet.org/fontdb.cgi 查找。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
pyfiglet -f isometric3 Kube

      ___           ___                         ___
     /__/|         /__/\         _____         /  /\
    |  |:|         \  \:\       /  /::\       /  /:/_
    |  |:|          \  \:\     /  /:/\:\     /  /:/ /\
  __|  |:|      ___  \  \:\   /  /:/~/::\   /  /:/ /:/_
 /__/\_|:|____ /__/\  \__\:\ /__/:/ /:/\:| /__/:/ /:/ /\
 \  \:\/:::::/ \  \:\ /  /:/ \  \:\/:/~/:/ \  \:\/:/ /:/
  \  \::/~~~~   \  \:\  /:/   \  \::/ /:/   \  \::/ /:/
   \  \:\        \  \:\/:/     \  \:\/:/     \  \:\/:/
    \  \:\        \  \::/       \  \::/       \  \::/
     \__\/         \__\/         \__\/         \__\/
  • 设置颜色
1
pyfiglet -f isometric3 -c BLUE  Kube

1
pyfiglet -f isometric3 -c RED  Kube

除此,还可以通过 from pyfiglet import Figlet 的方式,在 Python 代码中渲染字体。