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 for 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.
This commit is contained in:
Jun Wu 2016-11-28 23:33:02 +00:00
parent de6eda0ab8
commit 45c2358700

View File

@ -946,15 +946,39 @@ class curseschunkselector(object):
self.linesprintedtopadsofar += linesprinted
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"""
if self.errorstr is not None:
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)
self.statuswin.resize(self.numstatuslines, self.xscreensize)