结构脚本的彩色输出

Grz*_*orz 5 python deployment fabric

我正在尝试从结构脚本中为输出着色,所以我做了类似这样的事情:

local("hg pull")
print(blue(local("hg update")))
local("hg status")
Run Code Online (Sandbox Code Playgroud)

我希望将'hg update'响应打印为蓝色,但我得到下一行'hg status'的结果为蓝色.

在Fabric文档中,有一些着色硬编码字符串的示例,它们按照我的预期工作.您对我如何只对一个本地命令进行颜色响应有什么建议吗?

Ric*_*kyA 6

这是我使用的:

local("hg pull")
res = local("hg update", capture=True)
print(blue(res))
local("hg status")
Run Code Online (Sandbox Code Playgroud)

[编辑]你还需要capture=True获取输出.