views:

55

answers:

1

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?

+1  A: 

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.

Niall C.