@@ -49,6 +49,7 @@ where
4949import Data.Word
5050import GHC.Generics
5151import Control.DeepSeq
52+import Text.Printf (printf)
5253import System.Environment (lookupEnv)
5354
5455import qualified System.Console.Terminfo as Terminfo
@@ -95,7 +96,7 @@ import Graphics.Vty.Attributes.Color240
9596-- reported then the color reproduction will be incorrect.
9697--
9798-- If the terminal reports <= 16 colors then the 240 color palette
98−-- points are only mapped to the 8 color palette. I'm not sure of
99+-- points are only mapped to the 8 color pallete. I'm not sure of
99100-- the RGB points for the "bright" colors which is why they are not
100101-- addressable via the 240 color palette.
101102--
@@ -157,13 +158,18 @@ brightMagenta= ISOColor 13
157158brightCyan = ISOColor 14
158159brightWhite = ISOColor 15
159160
161+-- TODO: test this with other terminals
160162linearColor :: Integral i => i -> i -> i -> Color
161−linearColor r g b = RGBColor r' g' b'
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'
162168 where
163− r' = fromIntegral (clamp r) :: Word8
164− g' = fromIntegral (clamp g) :: Word8
165− b' = fromIntegral (clamp b) :: Word8
166− clamp = min 255 . max 0
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'
167173
168174srgbColor :: Integral i => i -> i -> i -> Color
169175srgbColor r g b =