changeset 30544:d4035372db8d

crecord: move status window text calculation to a separate method We will do some changes there in the next patches. The new method would also be the "source of truth" of the content of the status window (so if the status window needs more than 2 lines, it would be calculated from the new method). Also, moved "statuswin.refresh" to make the code compact and easier to read.
author Jun Wu <quark@fb.com>
date Mon, 28 Nov 2016 23:12:54 +0000
parents 03fae9048fa1
children f3cff00c7a00
files mercurial/crecord.py
diffstat 1 files changed, 16 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/crecord.py	Mon Nov 28 04:34:01 2016 -0800
+++ b/mercurial/crecord.py	Mon Nov 28 23:12:54 2016 +0000
@@ -946,6 +946,17 @@
         self.linesprintedtopadsofar += linesprinted
         return t
 
+    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")]
+        return [util.ellipsis(l, self.xscreensize - 1) for l in lines]
+
     def updatescreen(self):
         self.statuswin.erase()
         self.chunkpad.erase()
@@ -954,25 +965,13 @@
 
         # print out the status lines at the top
         try:
-            if self.errorstr is not None:
-                printstring(self.statuswin, self.errorstr, pairname='legend')
-                printstring(self.statuswin, 'Press any key to continue',
-                            pairname='legend')
-                self.statuswin.refresh()
-                return
-            line1 = _("SELECT CHUNKS: (j/k/up/dn/pgup/pgdn) move cursor; "
-                      "(space/A) toggle hunk/all; (e)dit hunk;")
-            line2 = _(" (f)old/unfold; (c)onfirm applied; (q)uit; (?) help "
-                      "| [X]=hunk applied **=folded, toggle [a]mend mode")
-
-            printstring(self.statuswin,
-                        util.ellipsis(line1, self.xscreensize - 1),
-                        pairname="legend")
-            printstring(self.statuswin,
-                        util.ellipsis(line2, self.xscreensize - 1),
-                        pairname="legend")
+            for line in self._getstatuslines():
+                printstring(self.statuswin, line, pairname="legend")
+            self.statuswin.refresh()
         except curses.error:
             pass
+        if self.errorstr is not None:
+            return
 
         # print out the patch in the remaining part of the window
         try:
@@ -985,9 +984,6 @@
         except curses.error:
             pass
 
-        # refresh([pminrow, pmincol, sminrow, smincol, smaxrow, smaxcol])
-        self.statuswin.refresh()
-
     def getstatusprefixstring(self, item):
         """
         create a string to prefix a line with which indicates whether 'item'