hgext/histedit.py
changeset 48203 8dd2422b0109
parent 48202 9006eafa0942
child 48204 33ece8857efa
--- a/hgext/histedit.py	Mon Oct 11 23:02:49 2021 -0700
+++ b/hgext/histedit.py	Mon Oct 11 23:04:29 2021 -0700
@@ -1517,39 +1517,11 @@
             b'main': (mainlen, maxx),
         }
 
-
-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 renderrules(rulesscr, state):
-        rules = state.rules
-        pos = state.pos
-        selected = state.selected
-        start = state.modes[MODE_RULES][b'line_offset']
+    def render_rules(self, rulesscr):
+        rules = self.rules
+        pos = self.pos
+        selected = self.selected
+        start = self.modes[MODE_RULES][b'line_offset']
 
         conflicts = [r.ctx for r in rules if r.conflicts]
         if len(conflicts) > 0:
@@ -1559,7 +1531,7 @@
             addln(rulesscr, -1, 0, line, curses.color_pair(COLOR_WARN))
 
         for y, rule in enumerate(rules[start:]):
-            if y >= state.page_height:
+            if y >= self.page_height:
                 break
             if len(rule.conflicts) > 0:
                 rulesscr.addstr(y, 0, b" ", curses.color_pair(COLOR_WARN))
@@ -1592,6 +1564,34 @@
 
         rulesscr.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 renderstring(win, state, output, diffcolors=False):
         maxy, maxx = win.getmaxyx()
         length = min(maxy - 1, len(output))
@@ -1679,7 +1679,7 @@
             elif curmode == MODE_HELP:
                 renderstring(mainwin, state, __doc__.strip().splitlines())
             else:
-                renderrules(mainwin, state)
+                state.render_rules(mainwin)
                 state.render_commit(commitwin)
             state.render_help(helpwin)
             curses.doupdate()