| Safe Haskell | None |
|---|---|
| Language | GHC2024 |
Lipstick.Color
Description
Colours, colour profiles and downsampling.
A Color is what you write in a style. It may be adaptive (lightDark,
complete), so it is only turned into a concrete TermColor when the
block is serialised and the terminal's ColorProfile is known.
Examples
Colours are written as strings (hex or a palette index), or with the functions and names below:
>>>["#7D56F4", "#fa0", "201", "5"] :: [Color][rgb 125 86 244,rgb 255 170 0,ansi256 201,ansi 5]>>>(rgb 125 86 244, ansi256 201, brightBlue)(rgb 125 86 244,ansi256 201,ansi 12)>>>hex "7D56F4"Just (rgb 125 86 244)>>>hex "nope"Nothing
An adaptive colour is resolved for a profile and background (dark or not) when it is printed:
>>>let accent = lightDark "#5A3FC0" "#B39DFF">>>resolveColor TrueColor True accentJust (TCRGB 179 157 255)>>>resolveColor TrueColor False accentJust (TCRGB 90 63 192)>>>resolveColor ANSI256 True "#7D56F4"Just (TC256 99)>>>resolveColor ANSI16 True "#7D56F4"Just (TC16 12)>>>resolveColor Ascii True "#7D56F4"Nothing>>>resolveColor ANSI16 True (complete "#7D56F4" "99" magenta)Just (TC16 5)
Gradients and adjustments:
>>>blend 3 ["#ff0000", "#0000ff"][rgb 255 0 0,rgb 140 83 162,rgb 0 0 255]>>>mix 0.25 black whitergb 29 29 29>>>darken 0.5 "#7D56F4"rgb 44 28 94>>>lighten 0.5 "#7D56F4"rgb 184 175 255>>>complementary "#7D56F4"rgb 138 128 0
Synopsis
- data Color
- rgb :: Word8 -> Word8 -> Word8 -> Color
- ansi :: Int -> Color
- ansi256 :: Int -> Color
- hex :: Text -> Maybe Color
- lightDark :: Color -> Color -> Color
- complete :: Color -> Color -> Color -> Color
- 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
- mix :: Double -> Color -> Color -> Color
- blend :: Int -> [Color] -> [Color]
- blend2D :: Int -> Int -> Double -> [Color] -> [[Color]]
- darken :: Double -> Color -> Color
- lighten :: Double -> Color -> Color
- complementary :: Color -> Color
- data TermColor
- data ColorProfile
- resolveColor :: ColorProfile -> Bool -> Color -> Maybe TermColor
- downsample :: ColorProfile -> TermColor -> Maybe TermColor
- termColorRGB :: TermColor -> (Word8, Word8, Word8)
Colours
A colour as written in a style.
Instances
| Eq Color Source # | |
| Ord Color Source # | |
| IsString Color Source # | Parses |
Defined in Lipstick.Internal.Color Methods fromString :: String -> Color # | |
| Show Color Source # | Shown as the functions that make it, since the constructors are not
exported: |
rgb :: Word8 -> Word8 -> Word8 -> Color Source #
A 24-bit colour from its red, green and blue components. On a terminal with fewer colours, the nearest one it has is used.
ansi256 :: Int -> Color Source #
A colour from the 256-colour palette; the index is taken modulo 256.
lightDark :: Color -> Color -> Color Source #
lightDark light dark is light on a light background and dark on
a dark one. The choice is made when the block is printed, from
envDarkBackground.
The 16 basic colours
What they look like is up to the terminal's palette. Where they are turned into RGB, xterm's palette is used.
brightBlack :: Color Source #
Basic colour 8: ansi 8.
brightGreen :: Color Source #
Basic colour 10: ansi 10.
brightYellow :: Color Source #
Basic colour 11: ansi 11.
brightBlue :: Color Source #
Basic colour 12: ansi 12.
brightMagenta :: Color Source #
Basic colour 13: ansi 13.
brightCyan :: Color Source #
Basic colour 14: ansi 14.
brightWhite :: Color Source #
Basic colour 15: ansi 15.
Manipulating colours
These work in the OkLab colour space, so steps look even. Palette colours are converted to RGB using xterm's palette, and adaptive colours are transformed in every variant.
mix :: Double -> Color -> Color -> Color Source #
mix t c1 c2 is c1 at 0, c2 at 1, and in between otherwise;
t is clamped to [0, 1].
Adaptive colours are mixed variant by variant: for each background and
each profile, with the matching variant of the other colour.
blend :: Int -> [Color] -> [Color] Source #
blend n stops is a gradient of n colours going evenly through the
stops, starting at the first and ending at the last.
blend2D :: Int -> Int -> Double -> [Color] -> [[Color]] Source #
blend2D width height angle stops is a two-dimensional gradient, as
height rows of width colours, at least one each way (no rows
without stops). The gradient runs through the stops along the
direction given by the angle in degrees, anticlockwise as in lipgloss
(0 is left to right, 90 bottom to top).
complementary :: Color -> Color Source #
The colour on the opposite side of the colour wheel, with the same lightness.
Terminal colours
A concrete colour a terminal understands.
Instances
| Eq TermColor Source # | |
| Ord TermColor Source # | |
| Show TermColor Source # | |
data ColorProfile Source #
What the output can display, from least to most capable.
Constructors
| NoTTY | Not a terminal: no escape sequences at all. |
| Ascii | Text attributes (bold, underline, …) but no colours. |
| ANSI16 | |
| ANSI256 | |
| TrueColor |
Instances
resolveColor :: ColorProfile -> Bool -> Color -> Maybe TermColor Source #
Resolve an adaptive colour for a profile and for whether the
background is dark, then downsample. Nothing means the profile cannot
show colours.
downsample :: ColorProfile -> TermColor -> Maybe TermColor Source #
Convert a colour to the closest one the profile supports.