mirror of https://github.com/aristocratos/bpytop
Fix broken color test by testing the values individually
Testing if the sum of the color values is within range is flawed because one out of range value might still not exceed the minimum or maximum value. Multiple out of range values can even pass the test by cancelling each other out. This patch tests each value individually and raises an exception on the first out of range value.pull/315/head
parent
9b732d4cfa
commit
2002d8049b
|
@ -1141,9 +1141,10 @@ class Color:
|
||||||
else:
|
else:
|
||||||
raise ValueError(f'RGB dec should be "0-255 0-255 0-255"')
|
raise ValueError(f'RGB dec should be "0-255 0-255 0-255"')
|
||||||
|
|
||||||
ct = self.dec[0] + self.dec[1] + self.dec[2]
|
for i in [0, 1, 2]:
|
||||||
if ct > 255*3 or ct < 0:
|
if not (0 <= self.dec[i] <= 255):
|
||||||
raise ValueError(f'RGB values out of range: {color}')
|
raise ValueError(f'One or more RGB values are out of range: {color}')
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
errlog.exception(str(e))
|
errlog.exception(str(e))
|
||||||
self.escape = ""
|
self.escape = ""
|
||||||
|
|
Loading…
Reference in New Issue