Basic data types
module System.Console.ANSI.Types ansi-terminal-types-1.1.3 · 10 declarations
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:
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:
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:
ANSI blink speeds: values other than NoBlink are not widely supported
Less than 150 blinks per minute
More than 150 blinks per minute
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.
Red :: Color
Blue :: Color
Cyan :: Color
ANSI's standard colors come in two intensities
Dull :: ColorIntensity
Vivid :: ColorIntensity
ANSI general console intensity: usually treated as setting the font style
(e.g. BoldIntensity causes text to be bold)
ANSI colors can be set on three different layers
ANSI Select Graphic Rendition (SGR) command
In respect of colors, there are three alternative commands:
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;
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
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.
SetColor :: ConsoleLayer -> ColorIntensity -> Color -> SGR
SetRGBColor :: ConsoleLayer -> (Colour Float) -> SGR
SetPaletteColor :: ConsoleLayer -> Word8 -> SGR
Cursor movement by character
| These functions yield "" when the number is 0 as, on some
terminals, a 0 parameter for the underlying 'ANSI' code specifies a
default parameter of 1.
IntNumber of lines or characters to move
IntNumber of lines or characters to move
IntNumber of lines or characters to move
IntNumber of lines or characters to move
Cursor movement by line
| These functions yield the equivalent of setCursorColumnCode 0 when
the number is 0 as, on some terminals, a 0 parameter for the
underlying 'ANSI' code specifies a default parameter of 1.
IntNumber of lines to move
IntNumber of lines to move
Directly changing cursor position
Code to move the cursor to the specified column. The column numbering is
0-based (that is, the left-most column is numbered 0).
Int0-based column to move to
Code to move the cursor to the specified position (row and column). The
position is 0-based (that is, the top-left corner is at row 0 column 0).
Int0-based row to move to
Int0-based column to move to
Saving, restoring and reporting cursor position
Code to emit the cursor position into the console input stream, immediately
after being recognised on the output stream, as:
ESC [ <cursor row> ; <cursor column> R
Note that the information that is emitted is 1-based (the top-left corner is
at row 1 column 1) but setCursorPositionCode is 0-based.
In isolation of getReportedCursorPosition or
getCursorPosition, this function may be of limited use
on Windows operating systems because of difficulties in obtaining the data
emitted into the console input stream.
Clearing parts of the screen
Enabling and disabling automatic line wrapping
| These functions control whether or not characters automatically wrap to
the next line when the cursor reaches the right border.
| These functions yield "" when the number is 0 as, on some
terminals, a 0 parameter for the underlying 'ANSI' code specifies a
default parameter of 1.
IntNumber of lines to scroll by
IntNumber of lines to scroll by
Using screen buffers
Reporting background or foreground colors
Code to emit the foreground or backgrond layer color into the console input
stream, immediately after being recognised on the output stream, as:
ESC ] <Ps> ; rgb: <red> ; <green> ; <blue> <ST>
where <Ps> is 10 for Foreground and 11 for Background; <red>,
<green> and <blue> are the color channel values in hexadecimal (4, 8,
12 and 16 bit values are possible, although 16 bit values are most common);
and <ST> is the STRING TERMINATOR (ST). ST depends on the terminal
software and may be the BEL character or ESC \ characters.
This function may be of limited, or no, use on Windows operating systems
because (1) the control character sequence is not supported on native
terminals (2) of difficulties in obtaining the data emitted into the
console input stream. See getReportedLayerColor.
Underlining is not supported.
Select Graphic Rendition mode: colors and other whizzy stuff
[SGR]Commands: these will typically be applied on top of the current
console SGR mode. An empty list of commands is equivalent to the list
[Reset]. Commands are applied left to right.
Cursor visibilty changes
Hyperlinks
| Some, but not all, terminals support hyperlinks - that is, clickable
text that points to a URI.
hyperlinkCode :: String -> String -> String
Code to introduce a hyperlink.
hyperlinkWithIdCode :: String -> String -> String -> String
Code to introduce a hyperlink with an identifier for the link. Some
terminals support an identifier, so that hyperlinks with the same identifier
are treated as connected.
StringIdentifier for the link
hyperlinkWithParamsCode :: [(String, String)] -> String -> String -> String
Code to introduce a hyperlink with (key, value) parameters. Some terminals
support an id parameter key, so that hyperlinks with the same id value
are treated as connected.
[(String, String)]Parameters
Changing the title
Code to set the terminal window title and the icon name (that is, the text
for the window in the Start bar, or similar).
StringNew window title and icon name
Utilities
colorToCode color returns the 0-based index of the color (one of the
eight colors in the ANSI standard).
Type synonym representing parameter values (without parameter substrings).
To represent a paramater value followed by a parameter substring, see
ParamWithSubs.
type SubParam = Maybe Int
Type synonym representing parameter elements of a parameter
substring. An empty parameter element (which represents a default value for
the parameter element) has value Nothing.
type ParamWithSubs = (Parameter, [SubParam])
Type synonym representing parameter values optionally followed by a
parameter substring. Parameter substrings were introduced by 13.1.8 of T.416
(03/93) for SGR parameter values 38 and 48 and have subsequently been adapted
for other uses.
csi :: [Parameter] -> String -> String
csi parameters controlFunction, where parameters is a list of Int,
returns the control sequence comprising the control function CONTROL
SEQUENCE INTRODUCER (CSI) followed by the parameter(s) (separated by ';')
and ending with the controlFunction character(s) that identifies the
control function. See csi' for a function that handles parameter values
that may be followed by a parameter substring.
[Parameter]List of parameters for the control sequence.
StringCharacter(s) that identify the control function.
csi' :: [ParamWithSubs] -> String -> String
Like csi but extended to parameters that may be followed by a parameter
substring. The parameter elements of a parameter substring are separated from
the parameter value and each other by ':'.
[ParamWithSubs]List of parameters (each of which may be followed by a parameter
substring).
StringCharacters(s) that identify the control function.
osc :: String -> String -> String
osc parameterS parametersT, where parameterS specifies the type of
operation to perform and parametersT is the other parameter(s) (if any),
returns the control sequence comprising the control function OPERATING SYSTEM
COMMAND (OSC) followed by the parameters (separated by ';') and ending with
the STRING TERMINATOR (ST) "\ESC\\".
sgrToCode :: SGR -> [Parameter]
sgrToCode sgr returns the parameter of the SELECT GRAPHIC RENDITION
(SGR) aspect identified by sgr. If the parameter is followed by a parameter
substring returns an empty list. See sgrToCode' for a function that handles
also parameter values that are followed by a parameter substring.
sgrToCode' :: SGR -> Either ParamWithSubs [Parameter]
sgrToCode' sgr returns the parameter of the SELECT GRAPHIC RENDITION
(SGR) aspect identified by sgr.