[PATCH] crecord: fixes the formatting of the select status in the status line

Filip Filmar filmil at gmail.com
Sun Aug 13 08:04:52 UTC 2017


# HG changeset patch
# User Filip Filmar <filmil at gmail.com>
# Date 1502608633 25200
#      Sun Aug 13 00:17:13 2017 -0700
# Node ID 4a5fd64feb902da51e7eb5759f4c1d3966186726
# Parent  03039ff3082b970e70f582e998a7287d1600e912
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'.

diff -r 03039ff3082b -r 4a5fd64feb90 mercurial/crecord.py
--- a/mercurial/crecord.py	Tue Aug 01 17:53:48 2017 +0200
+++ b/mercurial/crecord.py	Sun Aug 13 00:17:13 2017 -0700
@@ -1010,6 +1010,13 @@
     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 @@
             _('c: confirm'),
             _('q: abort'),
             _('arrow keys: move/expand/collapse'),
-            _('space: deselect') if selected else _('space: select'),
+            selectedlabel,
             _('?: help'),
         ]
         return segments


More information about the Mercurial-devel mailing list