Why isn't pagination enabled by default for hg log? [was - Re: | less or more don't display colors]

Tony Mechelynck antoine.mechelynck at gmail.com
Thu Feb 4 21:42:59 UTC 2016


On Thu, Feb 4, 2016 at 1:45 PM, Jaikiran Pai <jai.forums2013 at gmail.com> wrote:
> One thing I have always wondered is why isn't pagination enabled by default
> (i.e. out of the box hg installation) in mercurial. For any real reasonable
> sized project, the logs are going to span more than a page. Git for example
> has pagination enabled by default for logs (I don't mean to make it a git vs
> hg thing).
>
> I understand there are ways to setup aliases/configs etc but it isn't always
> feasible to do that. For example, given the nature of my work, most of the
> times, I have to ssh into various systems and browse the mercurial repos on
> those systems. I can't expect those aliases/configs to be setup there to be
> able to get a nice paginated output from hg log. I also realize that I can
> always do "hg log | less" to get pagination, but I'm curious why this isn't
> a default out of the box feature. Is there something that prevents it from
> being implemented as an enhancement in future releases?
>
> -Jaikiran
>
>
> On Tuesday 02 February 2016 12:59 AM, Martin Geisler wrote:
>
>
>
> On Mon, Feb 1, 2016 at 7:28 PM, Uwe Brauer <oub at mat.ucm.es> wrote:
>>
>> Hello
>>
>> I have the following alias (found somewhere on the web)
>> lg = log --template "{label('custom.rev',
>> rev)}\t{label('custom.phase',phase)}\t{label('custom.tag',tags)}\t{desc|firstline}
>> {label('custom.age', date|age)} {label('custom.user', author|user)}\n"
>>
>> That produces a very nice colored output.
>>
>> However, since the output is very large,  I run
>>
>>  hg lg | more
>>
>> But then  the colors are not displayed (using less the same occurs)
>>
>> Is there any possibility to display colors in this stetting?
>
>
> The color extension turns off the colors by default when it detects that
> stdout doesn't go to the terminal.
>
> You can force colors by adding --color=always to the command line in your
> alias.
>
> Alternatively, I would suggest using the pager extension
> (https://www.mercurial-scm.org/wiki/PagerExtension). That allows you to make
> certain commands always use a pager and color will then be shown as well. I
> use this configuration for pager:
>
> [pager]
> pager = less -RFSX
>
> Read the man page for less and adjust the flags as necessary -- the '-R'
> flag is what makes less pass ANSI color codes through.
>
>
> --
> Martin Geisler

You can set up a .hgrc file in your home directory, with an
[extensions] section including
    color =
    pager =
and a [pager] section set to whatever you like. This way, IIUC, your
preferred settings will be active whenever you run Mercurial on any
repository whatsoever. For instance, the [pager] section in my ~/.hgrc
is as follows (on Linux):

[pager]
pager           = less
attend          = annotate, cat, diff, qdiff, export, help, log, glog, config

My $LESS environment variable is also set to -M -I -R so these options
(extra verbose prompt; searches are caseless; pass ANSI color codes to
the terminal) apply whenever I run less, not only from Mercurial.

Of course, if you are on Windows and less is not installed on your
system, you will have to choose a different default pager. "view -"
(without the quotes; or "vim -R -", also without the quotes) might be
a possibility (after installing Vim, which runs on most platforms
including, among others, Windows, Linux and Mac).

Best regards,
Tony.



More information about the Mercurial mailing list