1-- Copyright 2009 Corey O'Connor
4-- For efficiency this can be, in the future, encoded into a single 32 bit word. The 32 bit word is
5-- first divided into 4 groups of 8 bits where:
6-- The first group codes what action should be taken with regards to the other groups.
9-- 00 => reset to default
12-- YY - foreground color action
13-- 00 => reset to default
16-- ZZ - background color action
17-- 00 => reset to default
22-- Next is the style flags
32-- Then the foreground color encoded into 8 bits.
33-- Then the background color encoded into 8 bits.
35module Graphics.Vty.Attributes
42-- | A display attribute defines the Color and Style of all the characters rendered after the
43-- attribute is applied.
45-- At most 256 colors, picked from a 240 and 16 color palette, are possible for the background and
46-- foreground. The 240 colors and 16 colors are points in different palettes. See Color for more
49 { style :: !(MaybeDefault Style)
50 , fore_color :: !(MaybeDefault Color)
51 , back_color :: !(MaybeDefault Color)
52 } deriving ( Eq, Show )
54-- | Specifies the display attributes such that the final style and color values do not depend on
55-- the previously applied display attribute. The display attributes can still depend on the
56-- terminal's default colors (unfortunately).
57data FixedAttr = FixedAttr
58 { fixed_style :: !Style
59 , fixed_fore_color :: !(Maybe Color)
60 , fixed_back_color :: !(Maybe Color)
61 } deriving ( Eq, Show )
63-- | The style and color attributes can either be the terminal defaults. Or be equivalent to the
64-- previously applied style. Or be a specific value.
65data Eq v => MaybeDefault v = Default | KeepCurrent | SetTo !v
68-- | Abstract data type representing a color.
70-- Currently the foreground and background color are specified as points in either a:
72-- * 16 color palette. Where the first 8 colors are equal to the 8 colors of the ISO 6429 (ANSI) 8
73-- color palette and the second 8 colors are bright/vivid versions of the first 8 colors.
75-- * 240 color palette. This palette is a regular sampling of the full RGB colorspace.
77-- The 8 ISO 6429 (ANSI) colors are as follows:
95-- The mapping from points in the 240 color palette to colors actually displayable by the terminal
96-- depends on the number of colors the terminal claims to support. Which is usually determined by
97-- the terminfo "colors" property. If this property is not being accurately reported then the color
98-- reproduction will be incorrect.
100-- If the terminal reports <= 16 colors then the 240 color palette points are only mapped to the 8
101-- color pallete. I'm not sure of the RGB points for the "bright" colors which is why they are not
102-- addressable via the 240 color palette.
104-- If the terminal reports > 16 colors then the 240 color palette points are mapped to the nearest
105-- points in a ("color count" - 16) subsampling of the 240 color palette.
107-- All of this assumes the terminals are behaving similarly to xterm and rxvt when handling colors.
108-- And that the individual colors have not been remapped by the user. There may be a way to verify
109-- this through terminfo but I don't know it.
111-- Seriously, terminal color support is INSANE.
112data Color = ISOColor !Word8 | Color240 !Word8
113 deriving ( Eq, Show )
115-- | Standard 8-color ANSI terminal color codes.
116black, red, green, yellow, blue, magenta, cyan, white :: Color
126-- | Bright/Vivid variants of the standard 8-color ANSI
127bright_black, bright_red, bright_green, bright_yellow :: Color
128bright_blue, bright_magenta, bright_cyan, bright_white :: Color
129bright_black = ISOColor 8
130bright_red = ISOColor 9
131bright_green = ISOColor 10
132bright_yellow = ISOColor 11
133bright_blue = ISOColor 12
134bright_magenta= ISOColor 13
135bright_cyan = ISOColor 14
136bright_white = ISOColor 15
138-- | Styles are represented as an 8 bit word. Each bit in the word is 1 if the style attribute
139-- assigned to that bit should be applied and 0 if the style attribute should not be applied.
142-- | The 6 possible style attributes:
156-- ( The invisible, protect, and altcharset display attributes some terminals support are not
157-- supported via VTY.)
158standout, underline, reverse_video, blink, dim, bold :: Style
166default_style_mask :: Style
167default_style_mask = 0x00
169style_mask :: Attr -> Word8
176-- | true if the given Style value has the specified Style set.
177has_style :: Style -> Style -> Bool
178has_style s bit_mask = ( s .&. bit_mask ) /= 0
180-- | Set the foreground color of an `Attr'.
181with_fore_color :: Attr -> Color -> Attr
182with_fore_color attr c = attr { fore_color = SetTo c }
184-- | Set the background color of an `Attr'.
185with_back_color :: Attr -> Color -> Attr
186with_back_color attr c = attr { back_color = SetTo c }
188-- | Add the given style attribute
189with_style :: Attr -> Style -> Attr
190with_style attr style_flag = attr { style = SetTo $ style_mask attr .|. style_flag }
192-- | Sets the style, background color and foreground color to the default values for the terminal.
193-- There is no easy way to determine what the default background and foreground colors are.
195def_attr = Attr Default Default Default
197-- | Keeps the style, background color and foreground color that was previously set. Used to
198-- override some part of the previous style.
200-- EG: current_style `with_fore_color` bright_magenta
202-- Would be the currently applied style (be it underline, bold, etc) but with the foreground color
203-- set to bright_magenta.
205current_attr = Attr KeepCurrent KeepCurrent KeepCurrent
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list