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

login
register
mail settings
Submitter Jun Wu
Date Nov. 23, 2016, 11:24 p.m.
Message ID <5894c146af1e3154f7b3.1479943479@x1c>
Download mbox | patch
Permalink /patch/17736/
State Accepted
Headers show

Comments

Jun Wu - Nov. 23, 2016, 11:24 p.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1479926126 0
#      Wed Nov 23 18:35:26 2016 +0000
# Node ID 5894c146af1e3154f7b327dce54a779bb419811a
# Parent  ed629f77d3616013c8216d99e90e02c47eccdb4f
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 5894c146af1e
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).
Yuya Nishihara - Nov. 26, 2016, 1:28 p.m.
On Wed, 23 Nov 2016 23:24:39 +0000, Jun Wu wrote:
> # HG changeset patch
> # User Jun Wu <quark@fb.com>
> # Date 1479926126 0
> #      Wed Nov 23 18:35:26 2016 +0000
> # Node ID 5894c146af1e3154f7b327dce54a779bb419811a
> # Parent  ed629f77d3616013c8216d99e90e02c47eccdb4f
> # Available At https://bitbucket.org/quark-zju/hg-draft
> #              hg pull https://bitbucket.org/quark-zju/hg-draft -r 5894c146af1e
> 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).
> 
> 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,21 +966,8 @@ class curseschunkselector(object):
>          # print out the status lines at the top
>          try:
> +            for line in self._getstatuslines():
> +                printstring(self.statuswin, line, pairname="legend")
>              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

Don't we need statuswin.refresh() here?
Jun Wu - Nov. 26, 2016, 11:36 p.m.
Excerpts from Yuya Nishihara's message of 2016-11-26 22:28:26 +0900:
> On Wed, 23 Nov 2016 23:24:39 +0000, Jun Wu wrote:
> > # HG changeset patch
> > # User Jun Wu <quark@fb.com>
> > # Date 1479926126 0
> > #      Wed Nov 23 18:35:26 2016 +0000
> > # Node ID 5894c146af1e3154f7b327dce54a779bb419811a
> > # Parent  ed629f77d3616013c8216d99e90e02c47eccdb4f
> > # Available At https://bitbucket.org/quark-zju/hg-draft 
> > #              hg pull https://bitbucket.org/quark-zju/hg-draft  -r 5894c146af1e
> > 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).
> > 
> > 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,21 +966,8 @@ class curseschunkselector(object):
> >          # print out the status lines at the top
> >          try:
> > +            for line in self._getstatuslines():
> > +                printstring(self.statuswin, line, pairname="legend")
> >              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
> 
> Don't we need statuswin.refresh() here?

Good catch. Will send V2 with commit message and this problem addressed.

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,21 +966,8 @@  class curseschunkselector(object):
         # print out the status lines at the top
         try:
+            for line in self._getstatuslines():
+                printstring(self.statuswin, line, pairname="legend")
             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")
         except curses.error:
             pass