crecord: fixes the formatting of the select status in the status line

The status line in the crecord has the "space" status field which has variable
length depending on the length of the status label in the language of choice.
In English, the status labels are "space: deselect" and "space:select".  The
"deselect" label is 2 glyphs longer.  This makes the terminal output jump
around if the terminal width is just right so that the shorter label makes
the status line 1 line long, and the longer label makes it 2 lines long.

This patch formats the selected status into a fixed-width field.  The field
width is the maximum of the lengths of the two possible labels, to account for
differing translations and label lengths.  This should make the label behavior
uniform across localizations.

There does not seem to be a test for crecord, so I verified the change manually
with a local build of 'hg'.
This commit is contained in:
Filip Filmar 2017-08-13 00:17:13 -07:00
parent 9eb2a84457
commit 5ff93579e2

View File

@ -1010,6 +1010,13 @@ class curseschunkselector(object):
def _getstatuslinesegments(self):
"""-> [str]. return segments"""
selected = self.currentselecteditem.applied
spaceselect = _('space: select')
spacedeselect = _('space: deselect')
# Format the selected label into a place as long as the longer of the
# two possible labels. This may vary by language.
spacelen = max(len(spaceselect), len(spacedeselect))
selectedlabel = '%-*s' % (spacelen,
spacedeselect if selected else spaceselect)
segments = [
_headermessages[self.operation],
'-',
@ -1017,7 +1024,7 @@ class curseschunkselector(object):
_('c: confirm'),
_('q: abort'),
_('arrow keys: move/expand/collapse'),
_('space: deselect') if selected else _('space: select'),
selectedlabel,
_('?: help'),
]
return segments