[PATCH 6 of 8] crecord: rewrite status line text (BC)

Jun Wu quark at fb.com
Wed Nov 23 18:24:41 EST 2016


# HG changeset patch
# User Jun Wu <quark at fb.com>
# Date 1479940063 0
#      Wed Nov 23 22:27:43 2016 +0000
# Node ID 9e7850a8ae79f7ccf1855a489d42d66dc1d949db
# Parent  d84ab5920899a914a225319130937befc6402d8a
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 9e7850a8ae79
crecord: rewrite status line text (BC)

Previously, we display fixed text in the 2-line status header. Now we want
to customize some word there to make the "revert" action clear. However, if
we simply replace the verb using '%s' like this:

  "SELECT CHUNKS: (j/k/up/dn/pgup/pgdn) move cursor; "
  "(space/A) toggle hunk/all; (e)dit hunk;"),
  " (f)old/unfold; (c)onfirm %s; (q)uit; (?) help " % verb
  "| [X]=hunk %s **=folded, toggle [a]mend mode" % verb

It could cause trouble ofr i18n - some languages may expect things like
"%(verb) confirm", for example.

Therefore, this patch chooses to break the hard-coded 2-line sentences into
"segment"s which could be translated (and replaced) separately.

To make my work easier, I'm also changing the content being displayed, to
make it cleaner and more friendly to (new) users, namely:

  - Replace "SELECT CHUNKS" to "Select hunks to record". Because:
    - To eliminate "hunk" / "chunk" inconsistency.
    - "record" is used in the "text" UI. Do not use "apply", to make it
      consistent.
    - To make it clear you are choosing what to apply, not revert, or
      discard etc. This is probably the most important information the user
      should know. So let's put it first.
    - "to apply" could be replaced to others depending on the operation.
      The follow-up patches will address them.
  - Move "[x]" and "**" legends first to explain the current interface. New
    users should understand what the legends mean, followed by what they can
    do in the interface.
  - Replace "j/k/up/dn/pgup/pgdn" with "arrow keys". Because:
    - "arrow keys" is more friendly to new users.
    - Mentioning "j/k" first may make emacs users angry. We should stay
      neutral about editors.
    - "pgup/pgdn" actually don't work very well. For example, within a hunk
      of 100-line insertion, "pgdn" just moves one single line.
    - Left/Right arrow keys are useful for movement and discovery of
      "expanding" a block.
  - Replace "fold/unfold" with "collapse/expand", "fold" is well known as
    a different meaning in histedit and evolve.
  - Replace "(space/A) toggle hunk/all" to "space: select". Because:
    - "A: toggle all" is not that useful
    - It's unclear how "hunk" could be "toggled" to a dumb user. Let's
      make it clear it's all about "select".
    - A follow-up will make it use "unselect" when we know the current item
      is selected.
  - Remove "(f)old". Use arrow keys instead.
  - Remove "toggle [a]mend mode". It's just confusing and could be useless.
  - Remove "(e)dit hunk". It's powerful but not friendly to new users.
  - Replace "(q)uit" to "q: abort" to make it clear you will lose changes.

The result looks like the following in a 72-char terminal:

  Select hunks to apply.  [x]=selected **=collapsed  c: confirm  q: abort
  arrow keys: move/expand/collapse  space: select  ?: help

If the terminal is 132-char wide, the text could fit in a single line.

diff --git a/mercurial/crecord.py b/mercurial/crecord.py
--- a/mercurial/crecord.py
+++ b/mercurial/crecord.py
@@ -947,4 +947,17 @@ class curseschunkselector(object):
         return t
 
+    def _getstatuslinesegments(self):
+        """-> [str]. return segments"""
+        segments = [
+            _('Select hunks to record.'),
+            _('[x]=selected **=collapsed'),
+            _('c: confirm'),
+            _('q: abort'),
+            _('arrow keys: move/expand/collapse'),
+            _('space: select'),
+            _('?: help'),
+        ]
+        return segments
+
     def _getstatuslines(self):
         """() -> [str]. return short help used in the top status window"""
@@ -952,8 +965,17 @@ class curseschunkselector(object):
             lines = [self.errorstr, _('Press any key to continue')]
         else:
-            lines = [_("SELECT CHUNKS: (j/k/up/dn/pgup/pgdn) move cursor; "
-                       "(space/A) toggle hunk/all; (e)dit hunk;"),
-                     _(" (f)old/unfold; (c)onfirm applied; (q)uit; (?) help "
-                       "| [X]=hunk applied **=folded, toggle [a]mend mode")]
+            # wrap segments to lines
+            segments = self._getstatuslinesegments()
+            width = self.xscreensize
+            lines = []
+            lastwidth = width
+            for s in segments:
+                w = encoding.colwidth(s)
+                if lastwidth + w + 2 >= width:
+                    lines.append(s)
+                    lastwidth = w
+                else:
+                    lines[-1] += '  ' + s
+                    lastwidth += w + 2
         if len(lines) != self.numstatuslines:
             self.numstatuslines = len(lines)


More information about the Mercurial-devel mailing list