1{-# LANGUAGE StandaloneDeriving #-}
3{-# LANGUAGE RankNTypes #-}
6-- Typically the values 'defAttr' or 'currentAttr' are modified to form attributes:
9-- defAttr `withForeColor` red
12-- Is the attribute that will set the foreground color to red and the background color to the
15-- This can then be used to build an image wiht a red foreground like so:
18-- string (defAttr `withForeColor` red) "this text will be red"
21-- The default attributes set by 'defAttr' have a presentation determined by the terminal. This is
22-- not something VTY can control. The user is free to define the color scheme of the terminal as
23-- they see fit. Up to the limits of the terminal anyways.
25-- The value 'currentAttr' will keep the attributes of whatever was output previously.
27-- \todo This API is very verbose IMO. I'd like something more succinct.
28module Graphics.Vty.Attributes ( module Graphics.Vty.Attributes
29 , module Graphics.Vty.Attributes.Color
30 , module Graphics.Vty.Attributes.Color240
39import Graphics.Vty.Attributes.Color
40import Graphics.Vty.Attributes.Color240
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 { attrStyle :: !(MaybeDefault Style)
50 , attrForeColor :: !(MaybeDefault Color)
51 , attrBackColor :: !(MaybeDefault Color)
52 } deriving ( Eq, Show )
54-- This could be encoded into a single 32 bit word. The 32 bit word is first divided
55-- into 4 groups of 8 bits where: The first group codes what action should be taken with regards to
59-- 00 => reset to default
62-- YY - foreground color action
63-- 00 => reset to default
66-- ZZ - background color action
67-- 00 => reset to default
72-- Next is the style flags
82-- Then the foreground color encoded into 8 bits.
83-- Then the background color encoded into 8 bits.
85instance Monoid Attr where
86 mempty = Attr mempty mempty mempty
88 Attr ( attrStyle attr0 `mappend` attrStyle attr1 )
89 ( attrForeColor attr0 `mappend` attrForeColor attr1 )
90 ( attrBackColor attr0 `mappend` attrBackColor attr1 )
92-- | Specifies the display attributes such that the final style and color values do not depend on
93-- the previously applied display attribute. The display attributes can still depend on the
94-- terminal's default colors (unfortunately).
95data FixedAttr = FixedAttr
96 { fixedStyle :: !Style
97 , fixedForeColor :: !(Maybe Color)
98 , fixedBackColor :: !(Maybe Color)
99 } deriving ( Eq, Show )
101-- | The style and color attributes can either be the terminal defaults. Or be equivalent to the
102-- previously applied style. Or be a specific value.
103data MaybeDefault v where
104 Default :: MaybeDefault v
105 KeepCurrent :: MaybeDefault v
106 SetTo :: forall v . ( Eq v, Show v ) => !v -> MaybeDefault v
108deriving instance Eq v => Eq (MaybeDefault v)
109deriving instance Eq v => Show (MaybeDefault v)
111instance Eq v => Monoid ( MaybeDefault v ) where
113 mappend Default Default = Default
114 mappend Default KeepCurrent = Default
115 mappend Default ( SetTo v ) = SetTo v
116 mappend KeepCurrent Default = Default
117 mappend KeepCurrent KeepCurrent = KeepCurrent
118 mappend KeepCurrent ( SetTo v ) = SetTo v
119 mappend ( SetTo _v ) Default = Default
120 mappend ( SetTo v ) KeepCurrent = SetTo v
121 mappend ( SetTo _ ) ( SetTo v ) = SetTo v
123-- | Standard 8-color ANSI terminal color codes.
124black, red, green, yellow, blue, magenta, cyan, white :: Color
134-- | Bright/Vivid variants of the standard 8-color ANSI
135brightBlack, brightRed, brightGreen, brightYellow :: Color
136brightBlue, brightMagenta, brightCyan, brightWhite :: Color
137brightBlack = ISOColor 8
138brightRed = ISOColor 9
139brightGreen = ISOColor 10
140brightYellow = ISOColor 11
141brightBlue = ISOColor 12
142brightMagenta= ISOColor 13
143brightCyan = ISOColor 14
144brightWhite = ISOColor 15
146-- | Styles are represented as an 8 bit word. Each bit in the word is 1 if the style attribute
147-- assigned to that bit should be applied and 0 if the style attribute should not be applied.
150-- | The 6 possible style attributes:
164-- ( The invisible, protect, and altcharset display attributes some terminals support are not
165-- supported via VTY.)
166standout, underline, reverseVideo, blink, dim, bold :: Style
174defaultStyleMask :: Style
175defaultStyleMask = 0x00
177styleMask :: Attr -> Word8
179 = case attrStyle attr of
184-- | true if the given Style value has the specified Style set.
185hasStyle :: Style -> Style -> Bool
186hasStyle s bitMask = ( s .&. bitMask ) /= 0
188-- | Set the foreground color of an `Attr'.
189withForeColor :: Attr -> Color -> Attr
190withForeColor attr c = attr { attrForeColor = SetTo c }
192-- | Set the background color of an `Attr'.
193withBackColor :: Attr -> Color -> Attr
194withBackColor attr c = attr { attrBackColor = SetTo c }
196-- | Add the given style attribute
197withStyle :: Attr -> Style -> Attr
198withStyle attr styleFlag = attr { attrStyle = SetTo $ styleMask attr .|. styleFlag }
200-- | Sets the style, background color and foreground color to the default values for the terminal.
201-- There is no easy way to determine what the default background and foreground colors are.
203defAttr = Attr Default Default Default
205instance Default Attr where
208-- | Keeps the style, background color and foreground color that was previously set. Used to
209-- override some part of the previous style.
211-- EG: current_style `withForeColor` brightMagenta
213-- Would be the currently applied style (be it underline, bold, etc) but with the foreground color
214-- set to brightMagenta.
216currentAttr = 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