on edd0945 help sign in
104 lines 2.9 kB history raw
1{-# LANGUAGE DeriveGeneric #-}
2{-# LANGUAGE DeriveAnyClass #-}
3module Graphics.Vty.Attributes.Color
4 ( Color(..)
5 , black
6 , red
7 , green
8 , yellow
9 , blue
10 , magenta
11 , cyan
12 , white
13 , brightBlack
14 , brightRed
15 , brightGreen
16 , brightYellow
17 , brightBlue
18 , brightMagenta
19 , brightCyan
20 , brightWhite
21 )
22where
24import Data.Word
25import GHC.Generics
26import Control.DeepSeq
28-- | Abstract data type representing a color.
29--
30-- Currently the foreground and background color are specified as points
31-- in either a:
32--
33-- * 16 color palette. Where the first 8 colors are equal to the 8
34-- colors of the ISO 6429 (ANSI) 8 color palette and the second 8
35-- colors are bright/vivid versions of the first 8 colors.
36--
37-- * 240 color palette. This palette is a regular sampling of the full
38-- RGB colorspace for the first 224 colors. The remaining 16 colors is
39-- a greyscale palette.
40--
41-- The 8 ISO 6429 (ANSI) colors are as follows:
42--
43-- 0. black
44--
45-- 1. red
46--
47-- 2. green
48--
49-- 3. yellow
50--
51-- 4. blue
52--
53-- 5. magenta
54--
55-- 6. cyan
56--
57-- 7. white
58--
59-- The mapping from points in the 240 color palette to colors actually
60-- displayable by the terminal depends on the number of colors the
61-- terminal claims to support. Which is usually determined by the
62-- terminfo "colors" property. If this property is not being accurately
63-- reported then the color reproduction will be incorrect.
64--
65-- If the terminal reports <= 16 colors then the 240 color palette
66-- points are only mapped to the 8 color pallete. I'm not sure of
67-- the RGB points for the "bright" colors which is why they are not
68-- addressable via the 240 color palette.
69--
70-- If the terminal reports > 16 colors then the 240 color palette
71-- points are mapped to the nearest points in a ("color count" - 16)
72-- subsampling of the 240 color palette.
73--
74-- All of this assumes the terminals are behaving similarly to xterm and
75-- rxvt when handling colors. And that the individual colors have not
76-- been remapped by the user. There may be a way to verify this through
77-- terminfo but I don't know it.
78--
79-- Seriously, terminal color support is INSANE.
80data Color = ISOColor !Word8 | Color240 !Word8
81 deriving ( Eq, Show, Read, Generic, NFData )
83-- | Standard 8-color ANSI terminal color codes.
84black, red, green, yellow, blue, magenta, cyan, white :: Color
85black = ISOColor 0
86red = ISOColor 1
87green = ISOColor 2
88yellow = ISOColor 3
89blue = ISOColor 4
90magenta= ISOColor 5
91cyan = ISOColor 6
92white = ISOColor 7
94-- | Bright/Vivid variants of the standard 8-color ANSI
95brightBlack, brightRed, brightGreen, brightYellow :: Color
96brightBlue, brightMagenta, brightCyan, brightWhite :: Color
97brightBlack = ISOColor 8
98brightRed = ISOColor 9
99brightGreen = ISOColor 10
100brightYellow = ISOColor 11
101brightBlue = ISOColor 12
102brightMagenta= ISOColor 13
103brightCyan = ISOColor 14
104brightWhite = ISOColor 15