System.Console.ANSI.Types

ansi-terminal-types-1.1: Types and functions used to represent SGR aspects

Safe Haskell | Safe
Language | Haskell2010

System.Console.ANSI.Types

Contents

- Types used to represent SGR aspects
- Constructors of xterm 256-color palette indices

Description

The 'ANSI' standards refer to the visual style of displaying characters as their 'graphic rendition'. The style includes the color of a character, its background, or (where supported) its underlining; the intensity (bold, normal or faint) of a character; or whether the character is italic or underlined (single, double, curly, dotted or dashed), blinking (slowly or rapidly) or visible or not. The 'ANSI' codes to establish the graphic rendition for subsequent text are referred to as SELECT GRAPHIC RENDITION (SGR).

This module exports types and functions used to represent SGR aspects. See also `setSGR` and related functions provided by the `ansi-terminal` package.

Synopsis

- data SGR
  - = Reset
  - | SetConsoleIntensity !ConsoleIntensity
  - | SetItalicized !Bool
  - | SetUnderlining !Underlining
  - | SetBlinkSpeed !BlinkSpeed
  - | SetVisible !Bool
  - | SetSwapForegroundBackground !Bool
  - | SetColor !ConsoleLayer !ColorIntensity !Color
  - | SetRGBColor !ConsoleLayer !(Colour Float)
  - | SetPaletteColor !ConsoleLayer !Word8
  - | SetDefaultColor !ConsoleLayer
- data ConsoleLayer
  - = Foreground
  - | Background
  - | Underlining
- data Color
  - = Black
  - | Red
  - | Green
  - | Yellow
  - | Blue
  - | Magenta
  - | Cyan
  - | White
- data ColorIntensity
  - = Dull
  - | Vivid
- data ConsoleIntensity
  - = BoldIntensity
  - | FaintIntensity
  - | NormalIntensity
- data Underlining
  - = SingleUnderline
  - | DoubleUnderline
  - | CurlyUnderline
  - | DottedUnderline
  - | DashedUnderline
  - | NoUnderline
- data BlinkSpeed
  - = SlowBlink
  - | RapidBlink
  - | NoBlink
- xterm6LevelRGB :: Int -> Int -> Int -> Word8
- xterm24LevelGray :: Int -> Word8
- xtermSystem :: ColorIntensity -> Color -> Word8

# Types used to represent SGR aspects

data SGR #

ANSI Select Graphic Rendition (SGR) command

In respect of colors, there are three alternative commands:

1. the 'ANSI' standards allow for eight standard colors (with two intensities). Windows and many other terminals (including xterm) allow the user to redefine the standard colors (so, for example `Vivid` `Green` may not correspond to bright green;
2. an extension of the standard that allows true colors (24 bit color depth) in RGB space. This is usually the best alternative for more colors; and
3. another extension that allows a palette of 256 colors, each color specified by an index. Xterm provides a protocol for a palette of 256 colors that many other terminals, including Windows 10, follow. Some terminals (including xterm) allow the user to redefine some or all of the palette colors.

Constructors

Reset | Default rendition, cancels the effect of any preceding occurrence of SGR (implementation-defined)
SetConsoleIntensity !ConsoleIntensity | Set the character intensity. Partially supported natively on Windows 10
SetItalicized !Bool | Set italicized. Not widely supported: sometimes treated as swapping foreground and background. Not supported natively on Windows 10
SetUnderlining !Underlining | Set or clear underlining. Partially supported natively on Windows 10
SetBlinkSpeed !BlinkSpeed | Set or clear character blinking. Not supported natively on Windows 10
SetVisible !Bool | Set revealed or concealed. Not widely supported. Not supported natively on Windows 10
SetSwapForegroundBackground !Bool | Set negative or positive image. Supported natively on Windows 10
SetColor !ConsoleLayer !ColorIntensity !Color | Set a color from the standard palette of 16 colors (8 colors by 2 color intensities). Many terminals allow the palette colors to be customised
SetRGBColor !ConsoleLayer !(Colour Float) | Set a true color (24 bit color depth). Supported natively on Windows 10 from the Creators Update (April 2017) Since: 0.7
SetPaletteColor !ConsoleLayer !Word8 | Set a color from a palette of 256 colors using a numerical index (0-based). Supported natively on Windows 10 from the Creators Update (April 2017) but not on legacy Windows native terminals. See `xtermSystem`, `xterm6LevelRGB` and `xterm24LevelGray` to construct indices based on xterm's standard protocol for a 256-color palette. Since: 0.9
SetDefaultColor !ConsoleLayer | Set a color to the default (implementation-defined) Since: 0.10

#### Instances

Instances details

Read SGR # |
Instance details Defined in System.Console.ANSI.Types Methods readsPrec :: Int -> ReadS SGR # readList :: ReadS [SGR] # readPrec :: ReadPrec SGR # readListPrec :: ReadPrec [SGR] #
Show SGR # |
Instance details Defined in System.Console.ANSI.Types Methods showsPrec :: Int -> SGR -> ShowS # show :: SGR -> String # showList :: [SGR] -> ShowS #
Eq SGR # |
Instance details Defined in System.Console.ANSI.Types Methods (==) :: SGR -> SGR -> Bool # (/=) :: SGR -> SGR -> Bool #

data ConsoleLayer #

ANSI colors can be set on three different layers

Constructors

Foreground |
Background |
Underlining | Not widely supported. Since: 1.1

#### Instances

Instances details

Bounded ConsoleLayer # |
Instance details Defined in System.Console.ANSI.Types Methods minBound :: ConsoleLayer # maxBound :: ConsoleLayer #
Enum ConsoleLayer # |
Instance details Defined in System.Console.ANSI.Types Methods succ :: ConsoleLayer -> ConsoleLayer # pred :: ConsoleLayer -> ConsoleLayer # toEnum :: Int -> ConsoleLayer # fromEnum :: ConsoleLayer -> Int # enumFrom :: ConsoleLayer -> [ConsoleLayer] # enumFromThen :: ConsoleLayer -> ConsoleLayer -> [ConsoleLayer] # enumFromTo :: ConsoleLayer -> ConsoleLayer -> [ConsoleLayer] # enumFromThenTo :: ConsoleLayer -> ConsoleLayer -> ConsoleLayer -> [ConsoleLayer] #
Ix ConsoleLayer # |
Instance details Defined in System.Console.ANSI.Types Methods range :: (ConsoleLayer, ConsoleLayer) -> [ConsoleLayer] # index :: (ConsoleLayer, ConsoleLayer) -> ConsoleLayer -> Int # unsafeIndex :: (ConsoleLayer, ConsoleLayer) -> ConsoleLayer -> Int # inRange :: (ConsoleLayer, ConsoleLayer) -> ConsoleLayer -> Bool # rangeSize :: (ConsoleLayer, ConsoleLayer) -> Int # unsafeRangeSize :: (ConsoleLayer, ConsoleLayer) -> Int #
Read ConsoleLayer # |
Instance details Defined in System.Console.ANSI.Types Methods readsPrec :: Int -> ReadS ConsoleLayer # readList :: ReadS [ConsoleLayer] # readPrec :: ReadPrec ConsoleLayer # readListPrec :: ReadPrec [ConsoleLayer] #
Show ConsoleLayer # |
Instance details Defined in System.Console.ANSI.Types Methods showsPrec :: Int -> ConsoleLayer -> ShowS # show :: ConsoleLayer -> String # showList :: [ConsoleLayer] -> ShowS #
Eq ConsoleLayer # |
Instance details Defined in System.Console.ANSI.Types Methods (==) :: ConsoleLayer -> ConsoleLayer -> Bool # (/=) :: ConsoleLayer -> ConsoleLayer -> Bool #
Ord ConsoleLayer # |
Instance details Defined in System.Console.ANSI.Types Methods compare :: ConsoleLayer -> ConsoleLayer -> Ordering # (<) :: ConsoleLayer -> ConsoleLayer -> Bool # (<=) :: ConsoleLayer -> ConsoleLayer -> Bool # (>) :: ConsoleLayer -> ConsoleLayer -> Bool # (>=) :: ConsoleLayer -> ConsoleLayer -> Bool # max :: ConsoleLayer -> ConsoleLayer -> ConsoleLayer # min :: ConsoleLayer -> ConsoleLayer -> ConsoleLayer #

data Color #

ANSI's eight standard colors. They come in two intensities, which are controlled by `ColorIntensity`. Many terminals allow the colors of the standard palette to be customised, so that, for example, `setSGR [ SetColor Foreground Vivid Green ]` may not result in bright green characters.

Constructors

Black |
Red |
Green |
Yellow |
Blue |
Magenta |
Cyan |
White |

#### Instances

Instances details

Bounded Color # |
Instance details Defined in System.Console.ANSI.Types Methods minBound :: Color # maxBound :: Color #
Enum Color # |
Instance details Defined in System.Console.ANSI.Types Methods succ :: Color -> Color # pred :: Color -> Color # toEnum :: Int -> Color # fromEnum :: Color -> Int # enumFrom :: Color -> [Color] # enumFromThen :: Color -> Color -> [Color] # enumFromTo :: Color -> Color -> [Color] # enumFromThenTo :: Color -> Color -> Color -> [Color] #
Ix Color # |
Instance details Defined in System.Console.ANSI.Types Methods range :: (Color, Color) -> [Color] # index :: (Color, Color) -> Color -> Int # unsafeIndex :: (Color, Color) -> Color -> Int # inRange :: (Color, Color) -> Color -> Bool # rangeSize :: (Color, Color) -> Int # unsafeRangeSize :: (Color, Color) -> Int #
Read Color # |
Instance details Defined in System.Console.ANSI.Types Methods readsPrec :: Int -> ReadS Color # readList :: ReadS [Color] # readPrec :: ReadPrec Color # readListPrec :: ReadPrec [Color] #
Show Color # |
Instance details Defined in System.Console.ANSI.Types Methods showsPrec :: Int -> Color -> ShowS # show :: Color -> String # showList :: [Color] -> ShowS #
Eq Color # |
Instance details Defined in System.Console.ANSI.Types Methods (==) :: Color -> Color -> Bool # (/=) :: Color -> Color -> Bool #
Ord Color # |
Instance details Defined in System.Console.ANSI.Types Methods compare :: Color -> Color -> Ordering # (<) :: Color -> Color -> Bool # (<=) :: Color -> Color -> Bool # (>) :: Color -> Color -> Bool # (>=) :: Color -> Color -> Bool # max :: Color -> Color -> Color # min :: Color -> Color -> Color #

data ColorIntensity #

ANSI's standard colors come in two intensities

Constructors

Dull |
Vivid |

#### Instances

Instances details

Bounded ColorIntensity # |
Instance details Defined in System.Console.ANSI.Types Methods minBound :: ColorIntensity # maxBound :: ColorIntensity #
Enum ColorIntensity # |
Instance details Defined in System.Console.ANSI.Types Methods succ :: ColorIntensity -> ColorIntensity # pred :: ColorIntensity -> ColorIntensity # toEnum :: Int -> ColorIntensity # fromEnum :: ColorIntensity -> Int # enumFrom :: ColorIntensity -> [ColorIntensity] # enumFromThen :: ColorIntensity -> ColorIntensity -> [ColorIntensity] # enumFromTo :: ColorIntensity -> ColorIntensity -> [ColorIntensity] # enumFromThenTo :: ColorIntensity -> ColorIntensity -> ColorIntensity -> [ColorIntensity] #
Ix ColorIntensity # |
Instance details Defined in System.Console.ANSI.Types Methods range :: (ColorIntensity, ColorIntensity) -> [ColorIntensity] # index :: (ColorIntensity, ColorIntensity) -> ColorIntensity -> Int # unsafeIndex :: (ColorIntensity, ColorIntensity) -> ColorIntensity -> Int # inRange :: (ColorIntensity, ColorIntensity) -> ColorIntensity -> Bool # rangeSize :: (ColorIntensity, ColorIntensity) -> Int # unsafeRangeSize :: (ColorIntensity, ColorIntensity) -> Int #
Read ColorIntensity # |
Instance details Defined in System.Console.ANSI.Types Methods readsPrec :: Int -> ReadS ColorIntensity # readList :: ReadS [ColorIntensity] # readPrec :: ReadPrec ColorIntensity # readListPrec :: ReadPrec [ColorIntensity] #
Show ColorIntensity # |
Instance details Defined in System.Console.ANSI.Types Methods showsPrec :: Int -> ColorIntensity -> ShowS # show :: ColorIntensity -> String # showList :: [ColorIntensity] -> ShowS #
Eq ColorIntensity # |
Instance details Defined in System.Console.ANSI.Types Methods (==) :: ColorIntensity -> ColorIntensity -> Bool # (/=) :: ColorIntensity -> ColorIntensity -> Bool #
Ord ColorIntensity # |
Instance details Defined in System.Console.ANSI.Types Methods compare :: ColorIntensity -> ColorIntensity -> Ordering # (<) :: ColorIntensity -> ColorIntensity -> Bool # (<=) :: ColorIntensity -> ColorIntensity -> Bool # (>) :: ColorIntensity -> ColorIntensity -> Bool # (>=) :: ColorIntensity -> ColorIntensity -> Bool # max :: ColorIntensity -> ColorIntensity -> ColorIntensity # min :: ColorIntensity -> ColorIntensity -> ColorIntensity #

data ConsoleIntensity #

ANSI general console intensity: usually treated as setting the font style (e.g. `BoldIntensity` causes text to be bold)

Constructors

BoldIntensity |
FaintIntensity | Not widely supported: sometimes treated as concealing text. Not supported natively on Windows 10
NormalIntensity |

#### Instances

Instances details

Bounded ConsoleIntensity # |
Instance details Defined in System.Console.ANSI.Types Methods minBound :: ConsoleIntensity # maxBound :: ConsoleIntensity #
Enum ConsoleIntensity # |
Instance details Defined in System.Console.ANSI.Types Methods succ :: ConsoleIntensity -> ConsoleIntensity # pred :: ConsoleIntensity -> ConsoleIntensity # toEnum :: Int -> ConsoleIntensity # fromEnum :: ConsoleIntensity -> Int # enumFrom :: ConsoleIntensity -> [ConsoleIntensity] # enumFromThen :: ConsoleIntensity -> ConsoleIntensity -> [ConsoleIntensity] # enumFromTo :: ConsoleIntensity -> ConsoleIntensity -> [ConsoleIntensity] # enumFromThenTo :: ConsoleIntensity -> ConsoleIntensity -> ConsoleIntensity -> [ConsoleIntensity] #
Ix ConsoleIntensity # |
Instance details Defined in System.Console.ANSI.Types Methods range :: (ConsoleIntensity, ConsoleIntensity) -> [ConsoleIntensity] # index :: (ConsoleIntensity, ConsoleIntensity) -> ConsoleIntensity -> Int # unsafeIndex :: (ConsoleIntensity, ConsoleIntensity) -> ConsoleIntensity -> Int # inRange :: (ConsoleIntensity, ConsoleIntensity) -> ConsoleIntensity -> Bool # rangeSize :: (ConsoleIntensity, ConsoleIntensity) -> Int # unsafeRangeSize :: (ConsoleIntensity, ConsoleIntensity) -> Int #
Read ConsoleIntensity # |
Instance details Defined in System.Console.ANSI.Types Methods readsPrec :: Int -> ReadS ConsoleIntensity # readList :: ReadS [ConsoleIntensity] # readPrec :: ReadPrec ConsoleIntensity # readListPrec :: ReadPrec [ConsoleIntensity] #
Show ConsoleIntensity # |
Instance details Defined in System.Console.ANSI.Types Methods showsPrec :: Int -> ConsoleIntensity -> ShowS # show :: ConsoleIntensity -> String # showList :: [ConsoleIntensity] -> ShowS #
Eq ConsoleIntensity # |
Instance details Defined in System.Console.ANSI.Types Methods (==) :: ConsoleIntensity -> ConsoleIntensity -> Bool # (/=) :: ConsoleIntensity -> ConsoleIntensity -> Bool #
Ord ConsoleIntensity # |
Instance details Defined in System.Console.ANSI.Types Methods compare :: ConsoleIntensity -> ConsoleIntensity -> Ordering # (<) :: ConsoleIntensity -> ConsoleIntensity -> Bool # (<=) :: ConsoleIntensity -> ConsoleIntensity -> Bool # (>) :: ConsoleIntensity -> ConsoleIntensity -> Bool # (>=) :: ConsoleIntensity -> ConsoleIntensity -> Bool # max :: ConsoleIntensity -> ConsoleIntensity -> ConsoleIntensity # min :: ConsoleIntensity -> ConsoleIntensity -> ConsoleIntensity #

data Underlining #

ANSI text underlining

Constructors

SingleUnderline |
DoubleUnderline | Not widely supported.
CurlyUnderline | Not widely supported. Since: 1.1
DottedUnderline | Not widely supported. Since: 1.1
DashedUnderline | Not widely supported. Since: 1.1
NoUnderline |

#### Instances

Instances details

Bounded Underlining # |
Instance details Defined in System.Console.ANSI.Types Methods minBound :: Underlining # maxBound :: Underlining #
Enum Underlining # |
Instance details Defined in System.Console.ANSI.Types Methods succ :: Underlining -> Underlining # pred :: Underlining -> Underlining # toEnum :: Int -> Underlining # fromEnum :: Underlining -> Int # enumFrom :: Underlining -> [Underlining] # enumFromThen :: Underlining -> Underlining -> [Underlining] # enumFromTo :: Underlining -> Underlining -> [Underlining] # enumFromThenTo :: Underlining -> Underlining -> Underlining -> [Underlining] #
Ix Underlining # |
Instance details Defined in System.Console.ANSI.Types Methods range :: (Underlining, Underlining) -> [Underlining] # index :: (Underlining, Underlining) -> Underlining -> Int # unsafeIndex :: (Underlining, Underlining) -> Underlining -> Int # inRange :: (Underlining, Underlining) -> Underlining -> Bool # rangeSize :: (Underlining, Underlining) -> Int # unsafeRangeSize :: (Underlining, Underlining) -> Int #
Read Underlining # |
Instance details Defined in System.Console.ANSI.Types Methods readsPrec :: Int -> ReadS Underlining # readList :: ReadS [Underlining] # readPrec :: ReadPrec Underlining # readListPrec :: ReadPrec [Underlining] #
Show Underlining # |
Instance details Defined in System.Console.ANSI.Types Methods showsPrec :: Int -> Underlining -> ShowS # show :: Underlining -> String # showList :: [Underlining] -> ShowS #
Eq Underlining # |
Instance details Defined in System.Console.ANSI.Types Methods (==) :: Underlining -> Underlining -> Bool # (/=) :: Underlining -> Underlining -> Bool #
Ord Underlining # |
Instance details Defined in System.Console.ANSI.Types Methods compare :: Underlining -> Underlining -> Ordering # (<) :: Underlining -> Underlining -> Bool # (<=) :: Underlining -> Underlining -> Bool # (>) :: Underlining -> Underlining -> Bool # (>=) :: Underlining -> Underlining -> Bool # max :: Underlining -> Underlining -> Underlining # min :: Underlining -> Underlining -> Underlining #

data BlinkSpeed #

ANSI blink speeds: values other than `NoBlink` are not widely supported

Constructors

SlowBlink | Less than 150 blinks per minute
RapidBlink | More than 150 blinks per minute
NoBlink |

#### Instances

Instances details

Bounded BlinkSpeed # |
Instance details Defined in System.Console.ANSI.Types Methods minBound :: BlinkSpeed # maxBound :: BlinkSpeed #
Enum BlinkSpeed # |
Instance details Defined in System.Console.ANSI.Types Methods succ :: BlinkSpeed -> BlinkSpeed # pred :: BlinkSpeed -> BlinkSpeed # toEnum :: Int -> BlinkSpeed # fromEnum :: BlinkSpeed -> Int # enumFrom :: BlinkSpeed -> [BlinkSpeed] # enumFromThen :: BlinkSpeed -> BlinkSpeed -> [BlinkSpeed] # enumFromTo :: BlinkSpeed -> BlinkSpeed -> [BlinkSpeed] # enumFromThenTo :: BlinkSpeed -> BlinkSpeed -> BlinkSpeed -> [BlinkSpeed] #
Ix BlinkSpeed # |
Instance details Defined in System.Console.ANSI.Types Methods range :: (BlinkSpeed, BlinkSpeed) -> [BlinkSpeed] # index :: (BlinkSpeed, BlinkSpeed) -> BlinkSpeed -> Int # unsafeIndex :: (BlinkSpeed, BlinkSpeed) -> BlinkSpeed -> Int # inRange :: (BlinkSpeed, BlinkSpeed) -> BlinkSpeed -> Bool # rangeSize :: (BlinkSpeed, BlinkSpeed) -> Int # unsafeRangeSize :: (BlinkSpeed, BlinkSpeed) -> Int #
Read BlinkSpeed # |
Instance details Defined in System.Console.ANSI.Types Methods readsPrec :: Int -> ReadS BlinkSpeed # readList :: ReadS [BlinkSpeed] # readPrec :: ReadPrec BlinkSpeed # readListPrec :: ReadPrec [BlinkSpeed] #
Show BlinkSpeed # |
Instance details Defined in System.Console.ANSI.Types Methods showsPrec :: Int -> BlinkSpeed -> ShowS # show :: BlinkSpeed -> String # showList :: [BlinkSpeed] -> ShowS #
Eq BlinkSpeed # |
Instance details Defined in System.Console.ANSI.Types Methods (==) :: BlinkSpeed -> BlinkSpeed -> Bool # (/=) :: BlinkSpeed -> BlinkSpeed -> Bool #
Ord BlinkSpeed # |
Instance details Defined in System.Console.ANSI.Types Methods compare :: BlinkSpeed -> BlinkSpeed -> Ordering # (<) :: BlinkSpeed -> BlinkSpeed -> Bool # (<=) :: BlinkSpeed -> BlinkSpeed -> Bool # (>) :: BlinkSpeed -> BlinkSpeed -> Bool # (>=) :: BlinkSpeed -> BlinkSpeed -> Bool # max :: BlinkSpeed -> BlinkSpeed -> BlinkSpeed # min :: BlinkSpeed -> BlinkSpeed -> BlinkSpeed #

# Constructors of xterm 256-color palette indices

xterm6LevelRGB :: Int -> Int -> Int -> Word8 #

Given xterm's standard protocol for a 256-color palette, returns the index to that part of the palette which is a 6 level (6x6x6) color cube of 216 RGB colors. Throws an error if any of the red, green or blue channels is outside the range 0 to 5. An example of use is:

    >>> setSGR [ SetPaletteColor $ xterm6LevelRGB 5 2 0 ] -- Dark Orange

Since: 0.9

xterm24LevelGray :: Int -> Word8 #

Given xterm's standard protocol for a 256-color palette, returns the index to that part of the palette which is a spectrum of 24 grays, from dark gray (0) to near white (23) (black and white are themselves excluded). Throws an error if the gray is outside of the range 0 to 23. An example of use is:

    >>> setSGR [ SetPaletteColor $ xterm24LevelGray 12 ] -- Gray50

Since: 0.9

xtermSystem :: ColorIntensity -> Color -> Word8 #

Given xterm's standard protocol for a 256-color palette, returns the index to that part of the palette which corresponds to the 'ANSI' standards' 16 standard, or 'system', colors (eight colors in two intensities). An example of use is:

    >>> setSGR [ SetPaletteColor $ xtermSystem Vivid Green ]

Since: 0.9