summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGerben Welter <gerben@welter.nu>2021-06-01 11:15:11 +0200
committerGerben Welter <gerben@welter.nu>2021-06-01 11:15:11 +0200
commit2002d8049b0392fd52445ff3ea375f8eea6a9e21 (patch)
tree1350f456bd00127f0d6344fc2da7c270e4870de9
parent9b732d4cfa054875c33926894b17b6e0fed6f64b (diff)
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.
-rwxr-xr-xbpytop.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/bpytop.py b/bpytop.py
index 21e252e..dfb92f7 100755
--- a/bpytop.py
+++ b/bpytop.py
@@ -1141,9 +1141,10 @@ class Color:
else:
raise ValueError(f'RGB dec should be "0-255 0-255 0-255"')
- ct = self.dec[0] + self.dec[1] + self.dec[2]
- if ct > 255*3 or ct < 0:
- raise ValueError(f'RGB values out of range: {color}')
+ for i in [0, 1, 2]:
+ if not (0 <= self.dec[i] <= 255):
+ raise ValueError(f'One or more RGB values are out of range: {color}')
+
except Exception as e:
errlog.exception(str(e))
self.escape = ""