on 175c235 help sign in
58 lines 1.9 kB history raw
1module Graphics.Vty.Attributes.Color where
3import Data.Word
5-- | Abstract data type representing a color.
6--
7-- Currently the foreground and background color are specified as points
8-- in either a:
9--
10-- * 16 color palette. Where the first 8 colors are equal to the 8
11-- colors of the ISO 6429 (ANSI) 8 color palette and the second 8
12-- colors are bright/vivid versions of the first 8 colors.
13--
14-- * 240 color palette. This palette is a regular sampling of the full
15-- RGB colorspace for the first 224 colors. The remaining 16 colors is
16-- a greyscale palette.
17--
18-- The 8 ISO 6429 (ANSI) colors are as follows:
19--
20-- 0. black
21--
22-- 1. red
23--
24-- 2. green
25--
26-- 3. yellow
27--
28-- 4. blue
29--
30-- 5. magenta
31--
32-- 6. cyan
33--
34-- 7. white
35--
36-- The mapping from points in the 240 color palette to colors actually
37-- displayable by the terminal depends on the number of colors the
38-- terminal claims to support. Which is usually determined by the
39-- terminfo "colors" property. If this property is not being accurately
40-- reported then the color reproduction will be incorrect.
41--
42-- If the terminal reports <= 16 colors then the 240 color palette
43-- points are only mapped to the 8 color pallete. I'm not sure of
44-- the RGB points for the "bright" colors which is why they are not
45-- addressable via the 240 color palette.
46--
47-- If the terminal reports > 16 colors then the 240 color palette
48-- points are mapped to the nearest points in a ("color count" - 16)
49-- subsampling of the 240 color palette.
50--
51-- All of this assumes the terminals are behaving similarly to xterm and
52-- rxvt when handling colors. And that the individual colors have not
53-- been remapped by the user. There may be a way to verify this through
54-- terminfo but I don't know it.
55--
56-- Seriously, terminal color support is INSANE.
57data Color = ISOColor !Word8 | Color240 !Word8
58 deriving ( Eq, Show, Read )