on master help sign in
Read COLORTERM env to determine truecolor support

The environment variable COLORTERM is used by terminal emulators to signify that they support truecolor in color escape sequences.

commitd304192e984e8c56ba6a4cfb11d419efd6e120aa authoru_quark <eleftherios.kritikos@gmail.com> dateTue 26 Nov 2019, 23:45 (7 years ago) parent43c6b3e
1 file changed+9−5
src/Graphics/Vty/Attributes/Color.hs+9−5
src/Graphics/Vty/Attributes/Color.hs+9−5
@@ -50,6 +50,7 @@ import Data.Word
5050import GHC.Generics
5151import Control.DeepSeq
5252import Text.Printf (printf)
53+import System.Environment (lookupEnv)
5354
5455import qualified System.Console.Terminfo as Terminfo
5556import Control.Exception (catch)
@@ -126,12 +127,15 @@ detectColorMode termName' = do
126127 (\(_ :: Terminfo.SetupTermError) -> return Nothing)
127128 let getCap cap = term >>= \t -> Terminfo.getCapability t cap
128129 termColors = fromMaybe 0 $ getCap (Terminfo.tiGetNum "colors")
130+ colorterm <- lookupEnv "COLORTERM"
129131 return $ if
130− | termColors < 8 -> NoColor
131− | termColors < 16 -> ColorMode8
132− | termColors == 16 -> ColorMode16
133− | termColors < 256 -> ColorMode240 (fromIntegral termColors - 16)
134− | otherwise -> ColorMode240 240
132+ | termColors < 8 -> NoColor
133+ | termColors < 16 -> ColorMode8
134+ | termColors == 16 -> ColorMode16
135+ | termColors < 256 -> ColorMode240 (fromIntegral termColors - 16)
136+ | colorterm == Just "truecolor" -> FullColor
137+ | colorterm == Just "24bit" -> FullColor
138+ | otherwise -> ColorMode240 240
135139
136140black, red, green, yellow, blue, magenta, cyan, white :: Color
137141black = ISOColor 0