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