我可以将自定义颜色添加到mercurial命令模板吗? [英] Can I add custom colors to mercurial command templates?
问题描述
我想为 hg log
使用自定义模板,如下所示:
hg log --template'{node | short} {desc} {{date | age} by {author}] \'n --color = always
这个默认的终端颜色是不太可读的,所以比如我想让节点变成红色,并且变为绿色。我怎样才能做到这一点?在git中,我可以像这样定义这种格式:
git log --pretty = format:'%Cred%h% Creset%Cgreen%s%Creset [%by%an]'
Mercurial?
AFAIK,没有办法直接在Mercurial中执行此操作,但如果您使用的是Unix-y系统您可以使用 ANSI转码来控制颜色。例如:
hg log --template\x1B [31m {node | short} \x1B [32m {desc } \x1B [0m\\\
会给你节点
以红色显示, desc
以绿色显示。
在Windows命令提示符下,必须启用 ColorExtension ,代码是color命令的参数(帮助颜色
在命令提示符下),所以相当于:
$ b $ $ p $ hg log - 模板\ x1B [4m {node | short} \x1B [0; 2m {desc}
<注意:在第二个转义序列中, 0
用于重置文本颜色, 2
是将其设置为绿色。如果没有 0
,看起来你会得到包含或颜色代码,在这种情况下,它将是黄色的。
I want to use customized template for hg log
which looks like this:
hg log --template '{node|short} {desc} [{date|age} by {author}]\'n --color=always
This in default terminal color is not very readable, so for instance I would like to make node red and desc green. How can I do this? In git I can define this kind of formatting like this:
git log --pretty=format:'%Cred%h%Creset %Cgreen%s%Creset [%ar by %an]'
Is a similar thing possible in mercurial?
AFAIK, there's no way to do this directly in Mercurial, but if you're on a Unix-y system you could use ANSI escape codes to control the colors. For example:
hg log --template "\x1B[31m{node|short} \x1B[32m{desc}\x1B[0m\n"
will give you the node
in red and the desc
in green.
On the Windows command prompt, you have to enable the ColorExtension and the codes are the parameters to the color command (help color
in the command prompt), so the equivalent would be:
hg log --template "\x1B[4m{node|short} \x1B[0;2m{desc}"
Note: in the second escape sequence, the 0
is to reset the text color and the 2
is to set it to green. Without the 0
, it seems you get an inclusive-or of the color codes, which in this case would be yellow.
这篇关于我可以将自定义颜色添加到mercurial命令模板吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!