changeset 43706:4323a32c7afe

histeditrule: split __bytes__ property into prefix and desc In order to be able to colourise the description of the rule, we need to have it as a separate bytestring. Curses doesn't make it easy to take existing text on the screen and give it different properties; we can only add new text with new properties.
author Jordi Gutiérrez Hermoso <jordigh@octave.org>
date Wed, 30 Oct 2019 19:27:09 -0400
parents 32048206e7be
children 1d29da62af76
files hgext/histedit.py
diffstat 1 files changed, 20 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/histedit.py	Fri Nov 15 22:22:55 2019 +0900
+++ b/hgext/histedit.py	Wed Oct 30 19:27:09 2019 -0400
@@ -1119,32 +1119,42 @@
         self.conflicts = []
 
     def __bytes__(self):
-        # Some actions ('fold' and 'roll') combine a patch with a previous one.
-        # Add a marker showing which patch they apply to, and also omit the
-        # description for 'roll' (since it will get discarded). Example display:
+        # Example display of several histeditrules:
         #
         #  #10 pick   316392:06a16c25c053   add option to skip tests
-        #  #11 ^roll  316393:71313c964cc5
+        #  #11 ^roll  316393:71313c964cc5   <RED>oops a fixup commit</RED>
         #  #12 pick   316394:ab31f3973b0d   include mfbt for mozilla-config.h
         #  #13 ^fold  316395:14ce5803f4c3   fix warnings
         #
         # The carets point to the changeset being folded into ("roll this
         # changeset into the changeset above").
+        return b'%s%s' % (self.prefix, self.desc)
+
+    __str__ = encoding.strmethod(__bytes__)
+
+    @property
+    def prefix(self):
+        # Some actions ('fold' and 'roll') combine a patch with a
+        # previous one. Add a marker showing which patch they apply
+        # to.
         action = ACTION_LABELS.get(self.action, self.action)
+
         h = self.ctx.hex()[0:12]
         r = self.ctx.rev()
-        desc = self.ctx.description().splitlines()[0].strip()
-        if self.action == b'roll':
-            desc = b''
-        return b"#%s %s %d:%s   %s" % (
+
+        return b"#%s %s %d:%s   " % (
             (b'%d' % self.origpos).ljust(2),
             action.ljust(6),
             r,
             h,
-            desc,
         )
 
-    __str__ = encoding.strmethod(__bytes__)
+    @property
+    def desc(self):
+        # This is split off from the prefix property so that we can
+        # separately make the description for 'roll' red (since it
+        # will get discarded).
+        return self.ctx.description().splitlines()[0].strip()
 
     def checkconflicts(self, other):
         if other.pos > self.pos and other.origpos <= self.origpos: