Patchwork D11640: chistedit: move renderpatch() and dependencies onto state class

login
register
mail settings
Submitter phabricator
Date Oct. 12, 2021, 5:07 p.m.
Message ID <differential-rev-PHID-DREV-4mm5nbdgjbb46xgke5xk-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/49964/
State Superseded
Headers show

Comments

phabricator - Oct. 12, 2021, 5:07 p.m.
martinvonz created this revision.
Herald added a reviewer: durin42.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D11640

AFFECTED FILES
  hgext/histedit.py

CHANGE DETAILS




To: martinvonz, durin42, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -1564,6 +1564,33 @@ 
 
         rulesscr.noutrefresh()
 
+    def render_string(self, win, output, diffcolors=False):
+        maxy, maxx = win.getmaxyx()
+        length = min(maxy - 1, len(output))
+        for y in range(0, length):
+            line = output[y]
+            if diffcolors:
+                if line and line[0] == b'+':
+                    win.addstr(
+                        y, 0, line, curses.color_pair(COLOR_DIFF_ADD_LINE)
+                    )
+                elif line and line[0] == b'-':
+                    win.addstr(
+                        y, 0, line, curses.color_pair(COLOR_DIFF_DEL_LINE)
+                    )
+                elif line.startswith(b'@@ '):
+                    win.addstr(y, 0, line, curses.color_pair(COLOR_DIFF_OFFSET))
+                else:
+                    win.addstr(y, 0, line)
+            else:
+                win.addstr(y, 0, line)
+        win.noutrefresh()
+
+    def render_patch(self, win):
+        start = self.modes[MODE_PATCH][b'line_offset']
+        content = self.modes[MODE_PATCH][b'patchcontents']
+        self.render_string(win, content[start:], diffcolors=True)
+
 
 def _chisteditmain(repo, rules, stdscr):
     try:
@@ -1592,33 +1619,6 @@ 
     except curses.error:
         pass
 
-    def renderstring(win, state, output, diffcolors=False):
-        maxy, maxx = win.getmaxyx()
-        length = min(maxy - 1, len(output))
-        for y in range(0, length):
-            line = output[y]
-            if diffcolors:
-                if line and line[0] == b'+':
-                    win.addstr(
-                        y, 0, line, curses.color_pair(COLOR_DIFF_ADD_LINE)
-                    )
-                elif line and line[0] == b'-':
-                    win.addstr(
-                        y, 0, line, curses.color_pair(COLOR_DIFF_DEL_LINE)
-                    )
-                elif line.startswith(b'@@ '):
-                    win.addstr(y, 0, line, curses.color_pair(COLOR_DIFF_OFFSET))
-                else:
-                    win.addstr(y, 0, line)
-            else:
-                win.addstr(y, 0, line)
-        win.noutrefresh()
-
-    def renderpatch(win, state):
-        start = state.modes[MODE_PATCH][b'line_offset']
-        content = state.modes[MODE_PATCH][b'patchcontents']
-        renderstring(win, state, content[start:], diffcolors=True)
-
     def drawvertwin(size, y, x):
         win = curses.newwin(size[0], size[1], y, x)
         y += size[0]
@@ -1675,9 +1675,9 @@ 
             helpwin.erase()
             mainwin.erase()
             if curmode == MODE_PATCH:
-                renderpatch(mainwin, state)
+                state.render_patch(mainwin)
             elif curmode == MODE_HELP:
-                renderstring(mainwin, state, __doc__.strip().splitlines())
+                state.render_string(mainwin, __doc__.strip().splitlines())
             else:
                 state.render_rules(mainwin)
                 state.render_commit(commitwin)