1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
|
---
title: terminal colors
...
# The `stdlib_ansi` module
[TOC]
## Introduction
Support terminal escape sequences to produce styled and colored terminal output.
## Derived types provided
### ``ansi_code`` type
The ``ansi_code`` type represent an ANSI escape sequence with a style, foreground
color and background color attribute. By default the instances of this type are
empty and represent no escape sequence.
#### Status
Experimental
#### Example
```fortran
{!example/ansi/example_ansi_color.f90!}
```
## Constants provided
### ``style_reset``
Style enumerator representing a reset escape code.
### ``style_bold``
Style enumerator representing a bold escape code.
### ``style_dim``
Style enumerator representing a dim escape code.
### ``style_italic``
Style enumerator representing an italic escape code.
### ``style_underline``
Style enumerator representing an underline escape code.
### ``style_blink``
Style enumerator representing a blink escape code.
### ``style_blink_fast``
Style enumerator representing a (fast) blink escape code.
### ``style_reverse``
Style enumerator representing a reverse escape code.
### ``style_hidden``
Style enumerator representing a hidden escape code.
### ``style_strikethrough``
Style enumerator representing a strike-through escape code.
### ``fg_color_black``
Foreground color enumerator representing a foreground black color escape code.
### ``fg_color_red``
Foreground color enumerator representing a foreground red color escape code.
### ``fg_color_green``
Foreground color enumerator representing a foreground green color escape code.
### ``fg_color_yellow``
Foreground color enumerator representing a foreground yellow color escape code.
### ``fg_color_blue``
Foreground color enumerator representing a foreground blue color escape code.
### ``fg_color_magenta``
Foreground color enumerator representing a foreground magenta color escape code.
### ``fg_color_cyan``
Foreground color enumerator representing a foreground cyan color escape code.
### ``fg_color_white``
Foreground color enumerator representing a foreground white color escape code.
### ``fg_color_default``
Foreground color enumerator representing a foreground default color escape code.
### ``bg_color_black``
Background color enumerator representing a background black color escape code.
### ``bg_color_red``
Background color enumerator representing a background red color escape code.
### ``bg_color_green``
Background color enumerator representing a background green color escape code.
### ``bg_color_yellow``
Background color enumerator representing a background yellow color escape code.
### ``bg_color_blue``
Background color enumerator representing a background blue color escape code.
### ``bg_color_magenta``
Background color enumerator representing a background magenta color escape code.
### ``bg_color_cyan``
Background color enumerator representing a background cyan color escape code.
### ``bg_color_white``
Background color enumerator representing a background white color escape code.
### ``bg_color_default``
Background color enumerator representing a background default color escape code.
## Procedures and methods provided
### ``to_string``
Generic interface to turn a style, foreground or background enumerator into an actual escape code string for printout.
#### Syntax
`string =` [[stdlib_ansi(module):to_string(interface)]] `(code)`
#### Class
Pure function.
#### Argument
``code``: Style, foreground or background code of ``ansi_code`` type,
this argument is ``intent(in)``.
#### Result value
The result is a default character string.
#### Status
Experimental
#### Example
```fortran
{!example/ansi/example_ansi_to_string.f90!}
```
### ``operator(+)``
Add two escape sequences, attributes in the right value override the left value ones.
#### Syntax
`code = lval + rval`
#### Class
Pure function.
#### Argument
``lval``: Style, foreground or background code of ``ansi_code`` type,
this argument is ``intent(in)``.
``rval``: Style, foreground or background code of ``ansi_code`` type,
this argument is ``intent(in)``.
#### Result value
The result is a style, foreground or background code of ``ansi_code`` type.
#### Status
Experimental
#### Example
```fortran
{!example/ansi/example_ansi_combine.f90!}
```
### ``operator(//)``
Concatenate an escape code with a string and turn it into an actual escape sequence
#### Syntax
`str = lval // rval`
#### Class
Pure function.
#### Argument
``lval``: Style, foreground or background code of ``ansi_code`` type or a character string,
this argument is ``intent(in)``.
``rval``: Style, foreground or background code of ``ansi_code`` type or a character string,
this argument is ``intent(in)``.
#### Result value
The result is a character string with the escape sequence prepended or appended.
#### Status
Experimental
#### Example
```fortran
{!example/ansi/example_ansi_concat.f90!}
```
|