@@ -49,7 +49,7 @@ where
4949import Data.Word
5050import GHC.Generics
5151import Control.DeepSeq
52−import System.Environment (lookupEnv)
52+import Text.Printf (printf)
5353
5454import qualified System.Console.Terminfo as Terminfo
5555import Control.Exception (catch)
@@ -95,7 +95,7 @@ import Graphics.Vty.Attributes.Color240
9595-- reported then the color reproduction will be incorrect.
9696--
9797-- 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
98+-- points are only mapped to the 8 color pallete. I'm not sure of
9999-- the RGB points for the "bright" colors which is why they are not
100100-- addressable via the 240 color palette.
101101--
@@ -126,15 +126,12 @@ detectColorMode termName' = do
126126 (\(_ :: Terminfo.SetupTermError) -> return Nothing)
127127 let getCap cap = term >>= \t -> Terminfo.getCapability t cap
128128 termColors = fromMaybe 0 $ getCap (Terminfo.tiGetNum "colors")
129− colorterm <- lookupEnv "COLORTERM"
130129 return $ if
131− | termColors < 8 -> NoColor
132− | termColors < 16 -> ColorMode8
133− | termColors == 16 -> ColorMode16
134− | termColors < 256 -> ColorMode240 (fromIntegral termColors - 16)
135− | colorterm == Just "truecolor" -> FullColor
136− | colorterm == Just "24bit" -> FullColor
137− | otherwise -> ColorMode240 240
130+ | termColors < 8 -> NoColor
131+ | termColors < 16 -> ColorMode8
132+ | termColors == 16 -> ColorMode16
133+ | termColors < 256 -> ColorMode240 (fromIntegral termColors - 16)
134+ | otherwise -> ColorMode240 240
138135
139136black, red, green, yellow, blue, magenta, cyan, white :: Color
140137black = ISOColor 0
@@ -157,13 +154,18 @@ brightMagenta= ISOColor 13
157154brightCyan = ISOColor 14
158155brightWhite = ISOColor 15
159156
157+-- TODO: test this with other terminals
160158linearColor :: Integral i => i -> i -> i -> Color
161−linearColor r g b = RGBColor r' g' b'
159+linearColor r g b
160+ | r < 0 || r > 255 = makeError
161+ | g < 0 || g > 255 = makeError
162+ | b < 0 || b > 255 = makeError
163+ | otherwise = RGBColor r' g' b'
162164 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
165+ r' = fromIntegral r :: Word8
166+ g' = fromIntegral g :: Word8
167+ b' = fromIntegral b :: Word8
168+ makeError = error $ printf "invalid value in rgbColor: (%d, %d, %d)" r' g' b'
167169
168170srgbColor :: Integral i => i -> i -> i -> Color
169171srgbColor r g b =