[PATCH 3 of 5] crecord: rewrite status line text (BC)

Jun Wu quark at fb.com
Mon Nov 28 18:52:07 EST 2016


# HG changeset patch
# User Jun Wu <quark at fb.com>
# Date 1480375982 0
#      Mon Nov 28 23:33:02 2016 +0000
# Node ID 527aa5f0098020651d0eb437538ed429380cd1ce
# Parent  bb6a5e96a536b37075e1c79f7b74d19dfe671827
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 527aa5f00980
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.

With the clean-up, 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 record, not revert, or
      discard etc. This is probably the most important information the user
      should know. So let's put it first.
    - "to record" 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 73-char-width terminal:

  Select hunks to record - [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,18 @@ 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 +966,18 @@ 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)
+                sep = ' ' * (1 + (s and s[0] not in '-['))
+                if lastwidth + w + len(sep) >= width:
+                    lines.append(s)
+                    lastwidth = w
+                else:
+                    lines[-1] += sep + s
+                    lastwidth += w + len(sep)
         if len(lines) != self.numstatuslines:
             self.numstatuslines = len(lines)


More information about the Mercurial-devel mailing list