adding log command to color extension

Martin Geisler mg at lazybytes.net
Fri Mar 19 05:27:27 CDT 2010


Stephen Mullins <smullins7 at gmail.com> writes:

> I've added support for the log command to the color extension. Let me
> know what you guys think.

Sorry about the slow review! I like the idea, but please see below.

> # HG changeset patch
> # User Steve Mullins <smullins7 at gmail.com>
> # Date 1267164276 28800
> # Node ID c0319676783187c6fde42cd59d1d9e22d0f2549c
> # Parent  011c6d0533d47479d4630f2ed5aae4eab2246b23
> color extension works for log command
>
> diff -r 011c6d0533d4 -r c03196767831 hgext/color.py
> --- a/hgext/color.py	Thu Feb 25 21:08:00 2010 -0800
> +++ b/hgext/color.py	Thu Feb 25 22:04:36 2010 -0800
> @@ -149,6 +149,13 @@
>                      'clean': ['none'],
>                      'copied': ['none'], }
>  
> +_log_effects = { 'changeset': ['white', 'bold'],
> +                 'parent': ['none'],
> +                 'tag': ['cyan'],
> +                 'user': ['magenta'],
> +                 'date': ['none'],
> +                 'summary': ['blue', 'bold'], }

Perhaps we should just colorize the "changeset:" line by default? That
way each significant record of the output will begin with a colored
line. Your color scheme is a bit too colorful for my taste :-)

>  def colorstatus(orig, ui, repo, *pats, **opts):
>      '''run the status command with colored output'''
>      return _colorstatuslike(_status_abbreviations, _status_effects,
> @@ -270,6 +277,25 @@
>      finally:
>          ui.write = oldwrite
>  
> +def colorlog(orig, ui, repo, *pats, **opts):
> +    '''run the log command with colored output'''
> +    delimiter = opts.get('print0') and '\0' or '\n'

This option is for log, right? The log command has no --print0 option. I
don't think the delimiter thing makes sense here.

> +    # run original command and capture its output
> +    ui.pushbuffer()
> +    retval = orig(ui, repo, *pats, **opts)
> +
> +    lines = [line for line in ui.popbuffer().split(delimiter) if line]

Here you remove all empty lines from the log output.

> +    # apply color to output and display it
> +    for line in lines:
> +        field = line.split(':')[0]
> +        effects = _log_effects.get(field, None)

Ah, now I know why I didn't see any colors... this wont work for
translated log output. On my computer, 'hg log' looks like this:

  ændring:     10734:7a0502a6f9a1
  mærkat:      tip
  forælder:    10731:71cf11f03b3d
  bruger:      Cédric Duval <cedricduval at free.fr>
  dato:        Mon Mar 15 22:37:38 2010 +0100
  uddrag:      patchbomb: --desc implies --intro

and so none of the key ever match...

> +        if effects:
> +            line = render_effects(line, effects)
> +        ui.write(line + delimiter)
> +    ui.write(delimiter)
> +
>  _diff_prefixes = [('diff', 'diffline'),
>                    ('copy', 'extended'),
>                    ('rename', 'extended'),
> @@ -296,7 +322,7 @@
>      '''Initialize the extension.'''
>      _setupcmd(ui, 'diff', commands.table, colordiff, _diff_effects)
>      _setupcmd(ui, 'incoming', commands.table, None, _diff_effects)
> -    _setupcmd(ui, 'log', commands.table, None, _diff_effects)
> +    _setupcmd(ui, 'log', commands.table, colorlog, _log_effects)
>      _setupcmd(ui, 'outgoing', commands.table, None, _diff_effects)
>      _setupcmd(ui, 'tip', commands.table, None, _diff_effects)
>      _setupcmd(ui, 'status', commands.table, colorstatus, _status_effects)
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel

-- 
Martin Geisler

Fast and powerful revision control: http://mercurial.selenic.com/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20100319/256005c7/attachment.pgp>


More information about the Mercurial-devel mailing list