[PATCH 1 of 3 V2] grep: give different labels to + and - symbols

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH 1 of 3 V2] grep: give different labels to + and - symbols

Jordi Gutiérrez Hermoso
# HG changeset patch
# User Jordi Gutiérrez Hermoso <[hidden email]>
# Date 1550262244 18000
#      Fri Feb 15 15:24:04 2019 -0500
# Node ID 14bb51f7e85c68b31a96ea6447f7439ac2d87e18
# Parent  37b33c34bf4f890857b5e8728febbc82a99368a5
grep: give different labels to + and - symbols

I find it more useful to give different colours to plus and minus, but
it's difficult to do so if the default output uses the same label for
both. The following augments the names of columns with some extra
labels, akin to the diff.inserted and diff.deleted labels for the diff
command.

This is done by adding an extra label field to the columns tuples.

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -2885,21 +2885,25 @@ def grep(ui, repo, pattern, *pats, **opt
             fm.plain(uipathfn(fn), label='grep.filename')
 
             cols = [
-                ('rev', '%d', rev, not plaingrep),
-                ('linenumber', '%d', l.linenum, opts.get('line_number')),
+                ('rev', '%d', rev, not plaingrep, ''),
+                ('linenumber', '%d', l.linenum, opts.get('line_number'), ''),
             ]
             if diff:
-                cols.append(('change', '%s', change, True))
+                cols.append(
+                    ('change', '%s', change, True,
+                     'grep.inserted ' if change == '+' else 'grep.deleted ')
+                )
             cols.extend([
-                ('user', '%s', formatuser(ctx.user()), opts.get('user')),
+                ('user', '%s', formatuser(ctx.user()), opts.get('user'), ''),
                 ('date', '%s', fm.formatdate(ctx.date(), datefmt),
-                 opts.get('date')),
+                 opts.get('date'), ''),
             ])
-            for name, fmt, data, cond in cols:
+            for name, fmt, data, cond, extra_label in cols:
                 if cond:
                     fm.plain(sep, label='grep.sep')
                 field = fieldnamemap.get(name, name)
-                fm.condwrite(cond, field, fmt, data, label='grep.%s' % name)
+                label = extra_label + ('grep.%s' % name)
+                fm.condwrite(cond, field, fmt, data, label=label)
             if not opts.get('files_with_matches'):
                 fm.plain(sep, label='grep.sep')
                 if not opts.get('text') and binary():
diff --git a/tests/test-grep.t b/tests/test-grep.t
--- a/tests/test-grep.t
+++ b/tests/test-grep.t
@@ -299,6 +299,10 @@ Test wdir
   color:3:+:orange
   color:2:-:orange
   color:1:+:orange
+  $ hg grep --diff orange --color=debug
+  [grep.filename|color][grep.sep|:][grep.rev|3][grep.sep|:][grep.inserted grep.change|+][grep.sep|:][grep.match|orange]
+  [grep.filename|color][grep.sep|:][grep.rev|2][grep.sep|:][grep.deleted grep.change|-][grep.sep|:][grep.match|orange]
+  [grep.filename|color][grep.sep|:][grep.rev|1][grep.sep|:][grep.inserted grep.change|+][grep.sep|:][grep.match|orange]
 
   $ hg grep --diff orange
   color:3:+:orange
_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Reply | Threaded
Open this post in threaded view
|

[PATCH 2 of 3 V2] color: give colours to the grep.inserted and grep.deleted labels

Jordi Gutiérrez Hermoso
# HG changeset patch
# User Jordi Gutiérrez Hermoso <[hidden email]>
# Date 1550263402 18000
#      Fri Feb 15 15:43:22 2019 -0500
# Node ID 1ef5e748ebdeec679227f78179bd36bb9b3a1667
# Parent  14bb51f7e85c68b31a96ea6447f7439ac2d87e18
color: give colours to the grep.inserted and grep.deleted labels

I find the "bold" makes it stand out a bit more when the green is next
to the line number.

Note that these labels are applied before the grep.change label, which
is now disabled. To get the old colour, users can restore

    [color]
    grep.change = green dim

to their hgrc.

diff --git a/mercurial/color.py b/mercurial/color.py
--- a/mercurial/color.py
+++ b/mercurial/color.py
@@ -78,11 +78,12 @@ except ImportError:
     'grep.match': 'red bold',
     'grep.linenumber': 'green',
     'grep.rev': 'green',
-    'grep.change': 'green',
     'grep.sep': 'cyan',
     'grep.filename': 'magenta',
     'grep.user': 'magenta',
     'grep.date': 'magenta',
+    'grep.inserted': 'green bold',
+    'grep.deleted': 'red bold',
     'bookmarks.active': 'green',
     'branches.active': 'none',
     'branches.closed': 'black bold',
diff --git a/tests/test-grep.t b/tests/test-grep.t
--- a/tests/test-grep.t
+++ b/tests/test-grep.t
@@ -304,6 +304,11 @@ Test wdir
   [grep.filename|color][grep.sep|:][grep.rev|2][grep.sep|:][grep.deleted grep.change|-][grep.sep|:][grep.match|orange]
   [grep.filename|color][grep.sep|:][grep.rev|1][grep.sep|:][grep.inserted grep.change|+][grep.sep|:][grep.match|orange]
 
+  $ hg grep --diff orange --color=yes
+  \x1b[0;35mcolor\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;32m3\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;32;1m+\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;31;1morange\x1b[0m (esc)
+  \x1b[0;35mcolor\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;32m2\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;31;1m-\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;31;1morange\x1b[0m (esc)
+  \x1b[0;35mcolor\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;32m1\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;32;1m+\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;31;1morange\x1b[0m (esc)
+
   $ hg grep --diff orange
   color:3:+:orange
   color:2:-:orange
_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Reply | Threaded
Open this post in threaded view
|

[PATCH 3 of 3 V2] color: change color of grep.rev label

Jordi Gutiérrez Hermoso
In reply to this post by Jordi Gutiérrez Hermoso
# HG changeset patch
# User Jordi Gutiérrez Hermoso <[hidden email]>
# Date 1550263757 18000
#      Fri Feb 15 15:49:17 2019 -0500
# Node ID 4b06afa25bb124da32fcaa56d2b81405b4163b61
# Parent  1ef5e748ebdeec679227f78179bd36bb9b3a1667
color: change color of grep.rev label

GNU grep uses green for line numbers as we do, but I sometimes get a
bit confused when I do `hg grep --diff -n` and get both line numbers
and revisions and don't know which one is which.

A different colour can help.

diff --git a/mercurial/color.py b/mercurial/color.py
--- a/mercurial/color.py
+++ b/mercurial/color.py
@@ -77,7 +77,7 @@ except ImportError:
 _defaultstyles = {
     'grep.match': 'red bold',
     'grep.linenumber': 'green',
-    'grep.rev': 'green',
+    'grep.rev': 'blue',
     'grep.sep': 'cyan',
     'grep.filename': 'magenta',
     'grep.user': 'magenta',
diff --git a/tests/test-grep.t b/tests/test-grep.t
--- a/tests/test-grep.t
+++ b/tests/test-grep.t
@@ -50,9 +50,9 @@ simple with color
 
   $ hg --config extensions.color= grep --config color.mode=ansi \
   >     --color=always port port -r tip:0
-  \x1b[0;35mport\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;32m4\x1b[0m\x1b[0;36m:\x1b[0mex\x1b[0;31;1mport\x1b[0m (esc)
-  \x1b[0;35mport\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;32m4\x1b[0m\x1b[0;36m:\x1b[0mva\x1b[0;31;1mport\x1b[0might (esc)
-  \x1b[0;35mport\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;32m4\x1b[0m\x1b[0;36m:\x1b[0mim\x1b[0;31;1mport\x1b[0m/ex\x1b[0;31;1mport\x1b[0m (esc)
+  \x1b[0;35mport\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;34m4\x1b[0m\x1b[0;36m:\x1b[0mex\x1b[0;31;1mport\x1b[0m (esc)
+  \x1b[0;35mport\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;34m4\x1b[0m\x1b[0;36m:\x1b[0mva\x1b[0;31;1mport\x1b[0might (esc)
+  \x1b[0;35mport\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;34m4\x1b[0m\x1b[0;36m:\x1b[0mim\x1b[0;31;1mport\x1b[0m/ex\x1b[0;31;1mport\x1b[0m (esc)
 
 simple templated
 
@@ -305,9 +305,9 @@ Test wdir
   [grep.filename|color][grep.sep|:][grep.rev|1][grep.sep|:][grep.inserted grep.change|+][grep.sep|:][grep.match|orange]
 
   $ hg grep --diff orange --color=yes
-  \x1b[0;35mcolor\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;32m3\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;32;1m+\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;31;1morange\x1b[0m (esc)
-  \x1b[0;35mcolor\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;32m2\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;31;1m-\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;31;1morange\x1b[0m (esc)
-  \x1b[0;35mcolor\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;32m1\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;32;1m+\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;31;1morange\x1b[0m (esc)
+  \x1b[0;35mcolor\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;34m3\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;32;1m+\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;31;1morange\x1b[0m (esc)
+  \x1b[0;35mcolor\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;34m2\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;31;1m-\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;31;1morange\x1b[0m (esc)
+  \x1b[0;35mcolor\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;34m1\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;32;1m+\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;31;1morange\x1b[0m (esc)
 
   $ hg grep --diff orange
   color:3:+:orange
_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 3 of 3 V2] color: change color of grep.rev label

Yuya Nishihara
On Mon, 18 Feb 2019 20:03:42 -0500, Jordi Gutiérrez Hermoso wrote:
> # HG changeset patch
> # User Jordi Gutiérrez Hermoso <[hidden email]>
> # Date 1550263757 18000
> #      Fri Feb 15 15:49:17 2019 -0500
> # Node ID 4b06afa25bb124da32fcaa56d2b81405b4163b61
> # Parent  1ef5e748ebdeec679227f78179bd36bb9b3a1667
> color: change color of grep.rev label

The series has already been queued.

> GNU grep uses green for line numbers as we do, but I sometimes get a
> bit confused when I do `hg grep --diff -n` and get both line numbers
> and revisions and don't know which one is which.

I've marked this as "(BC)" since this is IMHO a significant change. Blue on
black is unreadable on my machine.
_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 3 of 3 V2] color: change color of grep.rev label

Jordi Gutiérrez Hermoso
On Wed, 2019-02-20 at 11:49 +0900, Yuya Nishihara wrote:

> I've marked this as "(BC)" since this is IMHO a significant change.
> Blue on black is unreadable on my machine.

It's kind of hard to predict what will be readable. Linux terminal
emulators usually let you define "blue" to be whatever you want.

I wasn't sure if colour changes were BC, but I did put them in
separate commits so they could easily be separately dropped. I'm okay
with not changing the default colours and just adding more stuff to my
config. The only part I really wanted was extra labels.

_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 3 of 3 V2] color: change color of grep.rev label

Yuya Nishihara
On Tue, 19 Feb 2019 23:11:13 -0500, Jordi Gutiérrez Hermoso wrote:
> On Wed, 2019-02-20 at 11:49 +0900, Yuya Nishihara wrote:
>
> > I've marked this as "(BC)" since this is IMHO a significant change.
> > Blue on black is unreadable on my machine.
>
> It's kind of hard to predict what will be readable. Linux terminal
> emulators usually let you define "blue" to be whatever you want.

Yes.

> I wasn't sure if colour changes were BC, but I did put them in
> separate commits so they could easily be separately dropped. I'm okay
> with not changing the default colours and just adding more stuff to my
> config. The only part I really wanted was extra labels.

I'm not against this change. My point is that changing colors generally makes
someone unhappy, which is IMHO a behavior change.
_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel