granite-0.7.4.0: Easy terminal plotting.
Copyright(c) 2025
LicenseMIT
Maintainermschavinda@gmail.com
Safe HaskellNone
LanguageGHC2021

Granite.Color

Description

Color primitives shared by the terminal and SVG backends.

Color is a 24-bit RGB value. The classic ANSI palette names (Black, BrightBlue, Default, …) are provided as bidirectional pattern synonyms that expand to fixed RGB triples, so they may be used both as expressions and in patterns exactly as before.

The two backends deliberately diverge on how a colour is realised:

  • the SVG backend renders the RGB exactly via colorHex;
  • the terminal backend approximates via ansiCode, which maps an arbitrary colour to the nearest of the 16 ANSI slots.

Because Color is now a plain RGB triple, its derived Show prints Color r g b rather than the alias name.

Synopsis

Documentation

data Color Source #

A 24-bit RGB colour.

Constructors

Color !Word8 !Word8 !Word8 

Bundled Patterns

pattern Black :: Color 
pattern Red :: Color 
pattern Green :: Color 
pattern Yellow :: Color 
pattern Blue :: Color 
pattern Magenta :: Color 
pattern Cyan :: Color 
pattern White :: Color 
pattern BrightBlack :: Color 
pattern BrightRed :: Color 
pattern BrightGreen :: Color 
pattern BrightYellow :: Color 
pattern BrightBlue :: Color 
pattern BrightMagenta :: Color 
pattern BrightCyan :: Color 
pattern BrightWhite :: Color 
pattern Default :: Color 

Instances

Instances details
Read Color Source # 
Instance details

Defined in Granite.Color

Show Color Source # 
Instance details

Defined in Granite.Color

Methods

showsPrec :: Int -> Color -> ShowS #

show :: Color -> String #

showList :: [Color] -> ShowS #

Eq Color Source # 
Instance details

Defined in Granite.Color

Methods

(==) :: Color -> Color -> Bool #

(/=) :: Color -> Color -> Bool #

parseHex :: Text -> Maybe Color Source #

Parse a "#rrggbb" (or "rrggbb") string into a Color. Returns Nothing on malformed input.

ansiCode :: Color -> Int Source #

ANSI escape code for a colour. The 16 named slots (plus Default) return their canonical code; any other colour maps to the nearest ANSI slot.

ansiOn :: Color -> Text Source #

Opening ANSI escape sequence selecting a colour (its nearest ANSI slot).

ansiOff :: Text Source #

ANSI reset escape sequence.

paint :: Color -> Char -> Text Source #

Wrap a character in ANSI on/off sequences. Spaces pass through unchanged.

colorHex :: Color -> Text Source #

Exact #rrggbb rendering of a colour, used by the SVG backend.

paletteColors :: [Color] Source #

Default palette for layered charts (scatter, line, bars, …).

pieColors :: [Color] Source #

Palette used by pie / box plots (categorical, more saturated).