on master help sign in
Clamp values to [0..255] instead of error
commitf4ddc2b71fd36653f69ed250ff356064965f0ea4 authoru_quark <eleftherios.kritikos@gmail.com> dateSun 20 Mar 2022, 16:55 (5 years ago) parent8c28483
1 file changed+5−11
src/Graphics/Vty/Attributes/Color.hs+5−11
src/Graphics/Vty/Attributes/Color.hs+5−11
@@ -49,7 +49,6 @@ where
4949import Data.Word
5050import GHC.Generics
5151import Control.DeepSeq
52−import Text.Printf (printf)
5352import System.Environment (lookupEnv)
5453
5554import qualified System.Console.Terminfo as Terminfo
@@ -158,18 +157,13 @@ brightMagenta= ISOColor 13
158157brightCyan = ISOColor 14
159158brightWhite = ISOColor 15
160159
161−-- TODO: test this with other terminals
162160linearColor :: Integral i => i -> i -> i -> Color
163−linearColor r g b
164− | r < 0 || r > 255 = makeError
165− | g < 0 || g > 255 = makeError
166− | b < 0 || b > 255 = makeError
167− | otherwise = RGBColor r' g' b'
161+linearColor r g b = RGBColor r' g' b'
168162 where
169− r' = fromIntegral r :: Word8
170− g' = fromIntegral g :: Word8
171− b' = fromIntegral b :: Word8
172− makeError = error $ printf "invalid value in rgbColor: (%d, %d, %d)" r' g' b'
163+ r' = fromIntegral (clamp r) :: Word8
164+ g' = fromIntegral (clamp g) :: Word8
165+ b' = fromIntegral (clamp b) :: Word8
166+ clamp = min 255 . max 0
173167
174168srgbColor :: Integral i => i -> i -> i -> Color
175169srgbColor r g b =