vty-5.25.1: A simple terminal UI library

Safe Haskell | Safe
Language | Haskell2010

Graphics.Vty.Attributes

Contents

- Styles
- Setting attribute colors
- Setting hyperlinks
- Colors

Description

Display attributes

Attributes have three components: a foreground color, a background color, and a style mask. The simplest attribute is the default attribute, or `defAttr`. Attributes can be modified with `withForeColor`, `withBackColor`, and `withStyle`, e.g.,

        defAttr `withForeColor` red

`Image` constructors often require an `Attr` to indicate the attributes used in the image, e.g.,

        string (defAttr `withForeColor` red) "this text will be red"

The appearance of `Image`s using `defAttr` is determined by the The terminal, so this is not something VTY can control. The user is free to The define the color scheme of the terminal as they see fit.

The value `currentAttr` will keep the attributes of whatever was output previously.

Synopsis

- data Attr = Attr {
  - attrStyle :: !(MaybeDefault Style)
  - attrForeColor :: !(MaybeDefault Color)
  - attrBackColor :: !(MaybeDefault Color)
  - attrURL :: !(MaybeDefault Text)
  }
- data FixedAttr = FixedAttr {
  - fixedStyle :: !Style
  - fixedForeColor :: !(Maybe Color)
  - fixedBackColor :: !(Maybe Color)
  - fixedURL :: !(Maybe Text)
  }
- data MaybeDefault v where
  - Default :: MaybeDefault v
  - KeepCurrent :: MaybeDefault v
  - SetTo :: forall v. (Eq v, Show v, Read v) => !v -> MaybeDefault v
- defAttr :: Attr
- currentAttr :: Attr
- type Style = Word8
- withStyle :: Attr -> Style -> Attr
- standout :: Style
- italic :: Style
- underline :: Style
- reverseVideo :: Style
- blink :: Style
- dim :: Style
- bold :: Style
- defaultStyleMask :: Style
- styleMask :: Attr -> Word8
- hasStyle :: Style -> Style -> Bool
- withForeColor :: Attr -> Color -> Attr
- withBackColor :: Attr -> Color -> Attr
- withURL :: Attr -> Text -> Attr
- data Color
  - = ISOColor !Word8
  - | Color240 !Word8
- black :: Color
- red :: Color
- green :: Color
- yellow :: Color
- blue :: Color
- magenta :: Color
- cyan :: Color
- white :: Color
- brightBlack :: Color
- brightRed :: Color
- brightGreen :: Color
- brightYellow :: Color
- brightBlue :: Color
- brightMagenta :: Color
- brightCyan :: Color
- brightWhite :: Color
- rgbColor :: Integral i => i -> i -> i -> Color
- color240CodeToRGB :: Word8 -> Maybe (Int, Int, Int)

# Documentation

data Attr Source #

A display attribute defines the Color and Style of all the characters rendered after the attribute is applied.

At most 256 colors, picked from a 240 and 16 color palette, are possible for the background and foreground. The 240 colors and 16 colors are points in different palettes. See Color for more information.

Constructors

Attr |

Fields

- attrStyle :: !(MaybeDefault Style)
- attrForeColor :: !(MaybeDefault Color)
- attrBackColor :: !(MaybeDefault Color)
- attrURL :: !(MaybeDefault Text)

Instances

Eq Attr Source # |
Instance details Defined in Graphics.Vty.Attributes Methods (==) :: Attr -> Attr -> Bool Source # (/=) :: Attr -> Attr -> Bool Source #
Read Attr Source # |
Instance details Defined in Graphics.Vty.Attributes Methods readsPrec :: Int -> ReadS Attr Source # readList :: ReadS [Attr] Source # readPrec :: ReadPrec Attr Source # readListPrec :: ReadPrec [Attr] Source #
Show Attr Source # |
Instance details Defined in Graphics.Vty.Attributes Methods showsPrec :: Int -> Attr -> ShowS Source # show :: Attr -> String Source # showList :: [Attr] -> ShowS Source #
Generic Attr Source # |
Instance details Defined in Graphics.Vty.Attributes Associated Types type Rep Attr :: Type -> Type Source # Methods from :: Attr -> Rep Attr x Source # to :: Rep Attr x -> Attr Source #
Semigroup Attr Source # |
Instance details Defined in Graphics.Vty.Attributes Methods (<>) :: Attr -> Attr -> Attr Source # sconcat :: NonEmpty Attr -> Attr Source # stimes :: Integral b => b -> Attr -> Attr Source #
Monoid Attr Source # |
Instance details Defined in Graphics.Vty.Attributes Methods mempty :: Attr Source # mappend :: Attr -> Attr -> Attr Source # mconcat :: [Attr] -> Attr Source #
NFData Attr Source # |
Instance details Defined in Graphics.Vty.Attributes Methods rnf :: Attr -> () Source #
type Rep Attr Source # |

Instance details

Defined in Graphics.Vty.Attributes

type Rep Attr = D1 (MetaData "Attr" "Graphics.Vty.Attributes" "vty-5.25.1-7oKAOTf5ibHBKcogdwktuc" False) (C1 (MetaCons "Attr" PrefixI True) ((S1 (MetaSel (Just "attrStyle") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 (MaybeDefault Style)) :*: S1 (MetaSel (Just "attrForeColor") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 (MaybeDefault Color))) :*: (S1 (MetaSel (Just "attrBackColor") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 (MaybeDefault Color)) :*: S1 (MetaSel (Just "attrURL") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 (MaybeDefault Text)))))

data FixedAttr Source #

Specifies the display attributes such that the final style and color values do not depend on the previously applied display attribute. The display attributes can still depend on the terminal's default colors (unfortunately).

Constructors

FixedAttr |

Fields

- fixedStyle :: !Style
- fixedForeColor :: !(Maybe Color)
- fixedBackColor :: !(Maybe Color)
- fixedURL :: !(Maybe Text)

Instances

Eq FixedAttr Source # |
Instance details Defined in Graphics.Vty.Attributes Methods (==) :: FixedAttr -> FixedAttr -> Bool Source # (/=) :: FixedAttr -> FixedAttr -> Bool Source #
Show FixedAttr Source # |
Instance details Defined in Graphics.Vty.Attributes Methods showsPrec :: Int -> FixedAttr -> ShowS Source # show :: FixedAttr -> String Source # showList :: [FixedAttr] -> ShowS Source #

data MaybeDefault v where Source #

The style and color attributes can either be the terminal defaults. Or be equivalent to the previously applied style. Or be a specific value.

Constructors

Default :: MaybeDefault v |
KeepCurrent :: MaybeDefault v |
SetTo :: forall v. (Eq v, Show v, Read v) => !v -> MaybeDefault v |

Instances

Eq v => Eq (MaybeDefault v) Source # |
Instance details Defined in Graphics.Vty.Attributes Methods (==) :: MaybeDefault v -> MaybeDefault v -> Bool Source # (/=) :: MaybeDefault v -> MaybeDefault v -> Bool Source #
(Eq v, Show v, Read v) => Read (MaybeDefault v) Source # |
Instance details Defined in Graphics.Vty.Attributes Methods readsPrec :: Int -> ReadS (MaybeDefault v) Source # readList :: ReadS [MaybeDefault v] Source # readPrec :: ReadPrec (MaybeDefault v) Source # readListPrec :: ReadPrec [MaybeDefault v] Source #
Eq v => Show (MaybeDefault v) Source # |
Instance details Defined in Graphics.Vty.Attributes Methods showsPrec :: Int -> MaybeDefault v -> ShowS Source # show :: MaybeDefault v -> String Source # showList :: [MaybeDefault v] -> ShowS Source #
Eq v => Semigroup (MaybeDefault v) Source # |
Instance details Defined in Graphics.Vty.Attributes Methods (<>) :: MaybeDefault v -> MaybeDefault v -> MaybeDefault v Source # sconcat :: NonEmpty (MaybeDefault v) -> MaybeDefault v Source # stimes :: Integral b => b -> MaybeDefault v -> MaybeDefault v Source #
Eq v => Monoid (MaybeDefault v) Source # |
Instance details Defined in Graphics.Vty.Attributes Methods mempty :: MaybeDefault v Source # mappend :: MaybeDefault v -> MaybeDefault v -> MaybeDefault v Source # mconcat :: [MaybeDefault v] -> MaybeDefault v Source #
NFData v => NFData (MaybeDefault v) Source # |
Instance details Defined in Graphics.Vty.Attributes Methods rnf :: MaybeDefault v -> () Source #

defAttr :: Attr Source #

Sets the style, background color and foreground color to the default values for the terminal. There is no easy way to determine what the default background and foreground colors are.

currentAttr :: Attr Source #

Keeps the style, background color and foreground color that was previously set. Used to override some part of the previous style.

EG: current_style `withForeColor` brightMagenta

Would be the currently applied style (be it underline, bold, etc) but with the foreground color set to brightMagenta.

# Styles

type Style = Word8 Source #

Styles are represented as an 8 bit word. Each bit in the word is 1 if the style attribute assigned to that bit should be applied and 0 if the style attribute should not be applied.

withStyle :: Attr -> Style -> Attr Source #

Add the given style attribute

standout :: Style Source #

The 7 possible style attributes:

- standout
- underline
- reverseVideo
- blink
- dim
- bold/bright
- italic

(The invisible, protect, and altcharset display attributes some terminals support are not supported via VTY.)

italic :: Style Source #

The 7 possible style attributes:

- standout
- underline
- reverseVideo
- blink
- dim
- bold/bright
- italic

(The invisible, protect, and altcharset display attributes some terminals support are not supported via VTY.)

underline :: Style Source #

The 7 possible style attributes:

- standout
- underline
- reverseVideo
- blink
- dim
- bold/bright
- italic

(The invisible, protect, and altcharset display attributes some terminals support are not supported via VTY.)

reverseVideo :: Style Source #

The 7 possible style attributes:

- standout
- underline
- reverseVideo
- blink
- dim
- bold/bright
- italic

(The invisible, protect, and altcharset display attributes some terminals support are not supported via VTY.)

blink :: Style Source #

The 7 possible style attributes:

- standout
- underline
- reverseVideo
- blink
- dim
- bold/bright
- italic

(The invisible, protect, and altcharset display attributes some terminals support are not supported via VTY.)

dim :: Style Source #

The 7 possible style attributes:

- standout
- underline
- reverseVideo
- blink
- dim
- bold/bright
- italic

(The invisible, protect, and altcharset display attributes some terminals support are not supported via VTY.)

bold :: Style Source #

The 7 possible style attributes:

- standout
- underline
- reverseVideo
- blink
- dim
- bold/bright
- italic

(The invisible, protect, and altcharset display attributes some terminals support are not supported via VTY.)

defaultStyleMask :: Style Source #

styleMask :: Attr -> Word8 Source #

hasStyle :: Style -> Style -> Bool Source #

true if the given Style value has the specified Style set.

# Setting attribute colors

withForeColor :: Attr -> Color -> Attr Source #

Set the foreground color of an `Attr`.

withBackColor :: Attr -> Color -> Attr Source #

Set the background color of an `Attr`.

# Setting hyperlinks

withURL :: Attr -> Text -> Attr Source #

Add a hyperlinked URL using the proposed escape sequences for hyperlinked URLs. These escape sequences are comparatively new and aren't widely supported in terminal emulators yet, but most terminal emulators that don't know about these sequences will ignore these sequences, and therefore this should fall back sensibly. In some cases they won't and this will result in garbage, so this is why hyperlinking is disabled by default, in which case this combinator has no observable effect. To enable it, enable `Hyperlink` mode on your Vty output interface.

# Colors

data Color Source #

Abstract data type representing a color.

Currently the foreground and background color are specified as points in either a:

- 16 color palette. Where the first 8 colors are equal to the 8 colors of the ISO 6429 (ANSI) 8 color palette and the second 8 colors are bright/vivid versions of the first 8 colors.
- 240 color palette. This palette is a regular sampling of the full RGB colorspace for the first 224 colors. The remaining 16 colors is a greyscale palette.

The 8 ISO 6429 (ANSI) colors are as follows:

1. black
2. red
3. green
4. yellow
5. blue
6. magenta
7. cyan
8. white

The mapping from points in the 240 color palette to colors actually displayable by the terminal depends on the number of colors the terminal claims to support. Which is usually determined by the terminfo "colors" property. If this property is not being accurately reported then the color reproduction will be incorrect.

If the terminal reports <= 16 colors then the 240 color palette points are only mapped to the 8 color pallete. I'm not sure of the RGB points for the "bright" colors which is why they are not addressable via the 240 color palette.

If the terminal reports > 16 colors then the 240 color palette points are mapped to the nearest points in a ("color count" - 16) subsampling of the 240 color palette.

All of this assumes the terminals are behaving similarly to xterm and rxvt when handling colors. And that the individual colors have not been remapped by the user. There may be a way to verify this through terminfo but I don't know it.

Seriously, terminal color support is INSANE.

Constructors

ISOColor !Word8 |
Color240 !Word8 |

Instances

Eq Color Source # |
Instance details Defined in Graphics.Vty.Attributes.Color Methods (==) :: Color -> Color -> Bool Source # (/=) :: Color -> Color -> Bool Source #
Read Color Source # |
Instance details Defined in Graphics.Vty.Attributes.Color Methods readsPrec :: Int -> ReadS Color Source # readList :: ReadS [Color] Source # readPrec :: ReadPrec Color Source # readListPrec :: ReadPrec [Color] Source #
Show Color Source # |
Instance details Defined in Graphics.Vty.Attributes.Color Methods showsPrec :: Int -> Color -> ShowS Source # show :: Color -> String Source # showList :: [Color] -> ShowS Source #
Generic Color Source # |
Instance details Defined in Graphics.Vty.Attributes.Color Associated Types type Rep Color :: Type -> Type Source # Methods from :: Color -> Rep Color x Source # to :: Rep Color x -> Color Source #
NFData Color Source # |
Instance details Defined in Graphics.Vty.Attributes.Color Methods rnf :: Color -> () Source #
type Rep Color Source # |

Instance details

Defined in Graphics.Vty.Attributes.Color

type Rep Color = D1 (MetaData "Color" "Graphics.Vty.Attributes.Color" "vty-5.25.1-7oKAOTf5ibHBKcogdwktuc" False) (C1 (MetaCons "ISOColor" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Word8)) :+: C1 (MetaCons "Color240" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Word8)))

black :: Color Source #

Standard 8-color ANSI terminal color codes.

red :: Color Source #

Standard 8-color ANSI terminal color codes.

green :: Color Source #

Standard 8-color ANSI terminal color codes.

yellow :: Color Source #

Standard 8-color ANSI terminal color codes.

blue :: Color Source #

Standard 8-color ANSI terminal color codes.

magenta :: Color Source #

Standard 8-color ANSI terminal color codes.

cyan :: Color Source #

Standard 8-color ANSI terminal color codes.

white :: Color Source #

Standard 8-color ANSI terminal color codes.

brightBlack :: Color Source #

Bright/Vivid variants of the standard 8-color ANSI

brightRed :: Color Source #

Bright/Vivid variants of the standard 8-color ANSI

brightGreen :: Color Source #

Bright/Vivid variants of the standard 8-color ANSI

brightYellow :: Color Source #

Bright/Vivid variants of the standard 8-color ANSI

brightBlue :: Color Source #

brightMagenta :: Color Source #

brightCyan :: Color Source #

brightWhite :: Color Source #

rgbColor :: Integral i => i -> i -> i -> Color Source #

Create a Vty `Color` (in the 240 color set) from an RGB triple. This function is lossy in the sense that we only internally support 240 colors but the #RRGGBB format supports 16^3 colors.

color240CodeToRGB :: Word8 -> Maybe (Int, Int, Int) Source #

Create a RGB triple from a value in the Color240 set.