Patchwork [1,of,5] crecord: move status window text calculation to a separate method

login
register
mail settings
Submitter Jun Wu
Date Nov. 28, 2016, 11:52 p.m.
Message ID <e48c90823ca48725263c.1480377125@x1c>
Download mbox | patch
Permalink /patch/17771/
State Accepted
Headers show

Comments

Jun Wu - Nov. 28, 2016, 11:52 p.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1480374774 0
#      Mon Nov 28 23:12:54 2016 +0000
# Node ID e48c90823ca48725263c5cc2040827c31d6e447b
# Parent  64b55bffc1c059eb4c11ca195b561ca8a287f59e
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r e48c90823ca4
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.
Yuya Nishihara - Nov. 29, 2016, 1:52 p.m.
On Mon, 28 Nov 2016 23:52:05 +0000, Jun Wu wrote:
> # HG changeset patch
> # User Jun Wu <quark@fb.com>
> # Date 1480374774 0
> #      Mon Nov 28 23:12:54 2016 +0000
> # Node ID e48c90823ca48725263c5cc2040827c31d6e447b
> # Parent  64b55bffc1c059eb4c11ca195b561ca8a287f59e
> # Available At https://bitbucket.org/quark-zju/hg-draft
> #              hg pull https://bitbucket.org/quark-zju/hg-draft -r e48c90823ca4
> crecord: move status window text calculation to a separate method

Looks good. Queued the series, thanks.

Patch

diff --git a/mercurial/crecord.py b/mercurial/crecord.py
--- a/mercurial/crecord.py
+++ b/mercurial/crecord.py
@@ -947,4 +947,15 @@  class curseschunkselector(object):
         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()
@@ -955,23 +966,11 @@  class curseschunkselector(object):
         # 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
@@ -986,7 +985,4 @@  class curseschunkselector(object):
             pass
 
-        # refresh([pminrow, pmincol, sminrow, smincol, smaxrow, smaxcol])
-        self.statuswin.refresh()
-
     def getstatusprefixstring(self, item):
         """