Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Formatting 我可以向mercurial命令模板添加自定义颜色吗?_Formatting_Mercurial - Fatal编程技术网

Formatting 我可以向mercurial命令模板添加自定义颜色吗?

Formatting 我可以向mercurial命令模板添加自定义颜色吗?,formatting,mercurial,Formatting,Mercurial,我想为hg log使用定制模板,如下所示: hg log --template '{node|short} {desc} [{date|age} by {author}]\'n --color=always git log --pretty=format:'%Cred%h%Creset %Cgreen%s%Creset [%ar by %an]' 这个默认的终端颜色不是很可读,所以例如,我想将节点设置为红色和desc绿色。我该怎么做?在git中,我可以这样定义这种格式: hg log --t

我想为
hg log
使用定制模板,如下所示:

hg log --template '{node|short} {desc} [{date|age} by {author}]\'n --color=always
git log --pretty=format:'%Cred%h%Creset %Cgreen%s%Creset [%ar by %an]'
这个默认的终端颜色不是很可读,所以例如,我想将节点设置为红色和desc绿色。我该怎么做?在git中,我可以这样定义这种格式:

hg log --template '{node|short} {desc} [{date|age} by {author}]\'n --color=always
git log --pretty=format:'%Cred%h%Creset %Cgreen%s%Creset [%ar by %an]'

类似的事情在mercurial中也可能发生吗?

AFAIK,在mercurial中无法直接做到这一点,但是如果您使用的是Unix-y系统,则可以使用它来控制颜色。例如:

hg log --template "\x1B[31m{node|short} \x1B[32m{desc}\x1B[0m\n"
将为您提供红色的
节点
,绿色的
desc

在Windows命令提示下,您必须启用,代码是color命令的参数(
help color
,在命令提示下),因此等效值为:

hg log --template "\x1B[4m{node|short} \x1B[0;2m{desc}"

注意:在第二个转义序列中,
0
将重置文本颜色,
2
将其设置为绿色。如果没有
0
,您似乎会得到一个包含or的颜色代码,在本例中为黄色。

截至2013年,Mercurial直接支持。您还可以在hg帮助模板上检查这一点

您必须在上激活颜色扩展。hgrc

[extensions]
color =
hg log --template "{label('custom.rev',node|short)}  {desc}  [{date|age} by {label('custom.author',author)}]\n"
然后添加一些自定义标签,以便稍后在模板上使用:

[color]
custom.rev = yellow
custom.author = bold
然后使用引用标签的模板(使用{label('labelname',field)}而不是{field}

[extensions]
color =
hg log --template "{label('custom.rev',node|short)}  {desc}  [{date|age} by {label('custom.author',author)}]\n"
上面的示例以黄色突出显示节点(修订版),以蓝色粗体突出显示提交的作者。一如既往,您可以在.hgrc上创建别名:

[alias]
customlog = log --template "{label('custom.rev',node|short)}  {desc}  [{date|age} by {label('custom.author',author)}]\n"
更新:测试版本2.5.4。
根据,this.

是否有一种方法可以为{diffstats}使用不同的颜色?例如:绿色表示+红色表示-?要查看Mercurial本身使用的内置标签,请使用
--color=debug
运行命令;例如
hg log-l1--color=debug
。可以在Windows上使用相同的机制。