yachalk/chalk 与固定宽度字符串的 str.format 方法冲突

yachalk/chalk conflicts with str.format method for fixed-width strings

在 Python 中,我想同时 (a) 使用 str.format method to print strings with a fixed width and (b) use yachalk/chalk (see also this answer) 为发送到终端的输出着色。

当我在没有yachalk的情况下使用str.format时,我成功实现了定宽输出。但是,当我将 yachalk 添加到混合中时,我得到了我想要的彩色输出,但是字符串全部 运行 在一起,忽略了固定宽度的格式。

这是我的测试用例代码,后面是终端输出的屏幕截图。

我是不是做错了什么? yachalk 与 str.format 不兼容吗?

from yachalk import chalk
s1 = "e4"
s2 = "c5"
s3 = "Nf3"
s = '{:8}'.format(s1) + '{:8}'.format(s2) + '{:8}'.format(s3)
c1 = chalk.yellow(s1)
c2 = chalk.yellow(s2)
c3 = chalk.yellow(s3)
c = '{:8}'.format(c1) + '{:8}'.format(c2) + '{:8}'.format(c3)
print(s)
print(c)

问题已解决。尽管我无法将 str.format 方法应用于 yachalk 的输出,但我可以应用 str.format 方法 首先 然后应用 yachalk.

from yachalk import chalk
s1 = "e4"
s2 = "c5"
s3 = "Nf3"
s = '{:8}'.format(s1) + '{:8}'.format(s2) + '{:8}'.format(s3)
c1 = chalk.yellow('{:8}'.format(s1))
c2 = chalk.yellow('{:8}'.format(s2))
c3 = chalk.yellow('{:8}'.format(s3))
c = c1 + c2 + c3
print(s)
print(c)

查看粘贴图形的输出: