changeset 48201:8ac61257c807

chistedit: move rendercommit() onto state class Differential Revision: https://phab.mercurial-scm.org/D11637
author Martin von Zweigbergk <martinvonz@google.com>
date Mon, 11 Oct 2021 22:51:58 -0700
parents b6fc7d188f68
children 9006eafa0942
files hgext/histedit.py
diffstat 1 files changed, 33 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/histedit.py	Mon Oct 11 22:47:37 2021 -0700
+++ b/hgext/histedit.py	Mon Oct 11 22:51:58 2021 -0700
@@ -1424,39 +1424,11 @@
             },
         }
 
-
-def _chisteditmain(repo, rules, stdscr):
-    try:
-        curses.use_default_colors()
-    except curses.error:
-        pass
-
-    # initialize color pattern
-    curses.init_pair(COLOR_HELP, curses.COLOR_WHITE, curses.COLOR_BLUE)
-    curses.init_pair(COLOR_SELECTED, curses.COLOR_BLACK, curses.COLOR_WHITE)
-    curses.init_pair(COLOR_WARN, curses.COLOR_BLACK, curses.COLOR_YELLOW)
-    curses.init_pair(COLOR_OK, curses.COLOR_BLACK, curses.COLOR_GREEN)
-    curses.init_pair(COLOR_CURRENT, curses.COLOR_WHITE, curses.COLOR_MAGENTA)
-    curses.init_pair(COLOR_DIFF_ADD_LINE, curses.COLOR_GREEN, -1)
-    curses.init_pair(COLOR_DIFF_DEL_LINE, curses.COLOR_RED, -1)
-    curses.init_pair(COLOR_DIFF_OFFSET, curses.COLOR_MAGENTA, -1)
-    curses.init_pair(COLOR_ROLL, curses.COLOR_RED, -1)
-    curses.init_pair(
-        COLOR_ROLL_CURRENT, curses.COLOR_BLACK, curses.COLOR_MAGENTA
-    )
-    curses.init_pair(COLOR_ROLL_SELECTED, curses.COLOR_RED, curses.COLOR_WHITE)
-
-    # don't display the cursor
-    try:
-        curses.curs_set(0)
-    except curses.error:
-        pass
-
-    def rendercommit(win, state):
+    def render_commit(self, win):
         """Renders the commit window that shows the log of the current selected
         commit"""
-        pos = state.pos
-        rules = state.rules
+        pos = self.pos
+        rules = self.rules
         rule = rules[pos]
 
         ctx = rule.ctx
@@ -1471,7 +1443,7 @@
         line = b"user:      %s" % ctx.user()
         win.addstr(2, 1, line[:length])
 
-        bms = repo.nodebookmarks(ctx.node())
+        bms = self.repo.nodebookmarks(ctx.node())
         line = b"bookmark:  %s" % b' '.join(bms)
         win.addstr(3, 1, line[:length])
 
@@ -1503,6 +1475,34 @@
         win.addstr(y, 1, conflictstr[:length])
         win.noutrefresh()
 
+
+def _chisteditmain(repo, rules, stdscr):
+    try:
+        curses.use_default_colors()
+    except curses.error:
+        pass
+
+    # initialize color pattern
+    curses.init_pair(COLOR_HELP, curses.COLOR_WHITE, curses.COLOR_BLUE)
+    curses.init_pair(COLOR_SELECTED, curses.COLOR_BLACK, curses.COLOR_WHITE)
+    curses.init_pair(COLOR_WARN, curses.COLOR_BLACK, curses.COLOR_YELLOW)
+    curses.init_pair(COLOR_OK, curses.COLOR_BLACK, curses.COLOR_GREEN)
+    curses.init_pair(COLOR_CURRENT, curses.COLOR_WHITE, curses.COLOR_MAGENTA)
+    curses.init_pair(COLOR_DIFF_ADD_LINE, curses.COLOR_GREEN, -1)
+    curses.init_pair(COLOR_DIFF_DEL_LINE, curses.COLOR_RED, -1)
+    curses.init_pair(COLOR_DIFF_OFFSET, curses.COLOR_MAGENTA, -1)
+    curses.init_pair(COLOR_ROLL, curses.COLOR_RED, -1)
+    curses.init_pair(
+        COLOR_ROLL_CURRENT, curses.COLOR_BLACK, curses.COLOR_MAGENTA
+    )
+    curses.init_pair(COLOR_ROLL_SELECTED, curses.COLOR_RED, curses.COLOR_WHITE)
+
+    # don't display the cursor
+    try:
+        curses.curs_set(0)
+    except curses.error:
+        pass
+
     def helplines(mode):
         if mode == MODE_PATCH:
             help = b"""\
@@ -1679,7 +1679,7 @@
                 renderstring(mainwin, state, __doc__.strip().splitlines())
             else:
                 renderrules(mainwin, state)
-                rendercommit(commitwin, state)
+                state.render_commit(commitwin)
             renderhelp(helpwin, state)
             curses.doupdate()
             # done rendering