Added selected style, changed comment style to 2

* handle reversed range specifiers
This commit is contained in:
Rob McMullen 2016-02-10 10:28:36 -08:00
parent 967ea446fb
commit 76c7028c0a

View File

@ -264,26 +264,25 @@ class DefaultSegment(object):
def tostring(self): def tostring(self):
return self.data.tostring() return self.data.tostring()
def get_style_bits(self, match=False, comment=False): def get_style_bits(self, match=False, comment=False, selected=False):
style_bits = 0 style_bits = 0
if match: if match:
style_bits |= 1 style_bits |= 1
if comment: if comment:
style_bits |= 2
if selected:
style_bits |= 0x80 style_bits |= 0x80
return style_bits return style_bits
def get_style_mask(self, match=False, comment=False): def get_style_mask(self, **kwargs):
style_mask = 0xff return 0xff ^ self.get_style_bits(**kwargs)
if match:
style_mask &= 0xfe
if comment:
style_mask &= 0x7f
return style_mask
def set_style_ranges(self, ranges, **kwargs): def set_style_ranges(self, ranges, **kwargs):
style_bits = self.get_style_bits(**kwargs) style_bits = self.get_style_bits(**kwargs)
s = self.style s = self.style
for start, end in ranges: for start, end in ranges:
if end < start:
start, end = end, start
s[start:end] |= style_bits s[start:end] |= style_bits
def clear_style_bits(self, **kwargs): def clear_style_bits(self, **kwargs):