@@ -15,24 +15,33 @@ Support terminal escape sequences to produce styled and colored terminal output.
15
15
# # Derived types provided
16
16
17
17
18
- # ## ``fg_color24 `` type
18
+ # ## ``ansi_color `` type
19
19
20
- The ``fg_color24`` type represent a true color (24-bit) foreground color.
21
- It contains the members ``red``, ``blue`` and ``green`` as default integer types.
20
+ The ``ansi_color`` type represent an ANSI escape sequence with a style, forground
21
+ color and background color attribute. By default the instances of this type are
22
+ empty and represent no escape sequence.
22
23
23
24
# ### Status
24
25
25
26
Experimental
26
27
28
+ # ### Example
27
29
28
- # ## ``bg_color24`` type
30
+ ` ` ` fortran
31
+ program demo_color
32
+ use stdlib_terminal_colors, only : fg_color_blue, style_bold, style_reset, ansi_color, &
33
+ & operator(//), operator(+)
34
+ implicit none
35
+ type(ansi_color) :: highlight, reset
29
36
30
- The ``bg_color24`` type represent a true color (24-bit) background color.
31
- It contains the members ``red``, ``blue`` and ``green`` as default integer types.
37
+ print '(a)', highlight // "Dull text message" // reset
32
38
33
- # ### Status
39
+ highlight = fg_color_blue + style_bold
40
+ reset = style_reset
34
41
35
- Experimental
42
+ print '(a)', highlight // "Colorful text message" // reset
43
+ end program demo_color
44
+ ` ` `
36
45
37
46
38
47
# # Constants provided
@@ -52,13 +61,11 @@ Style enumerator representing a bold escape code.
52
61
Style enumerator representing a dim escape code.
53
62
54
63
55
-
56
64
# ## ``style_italic``
57
65
58
66
Style enumerator representing an italic escape code.
59
67
60
68
61
-
62
69
# ## ``style_underline``
63
70
64
71
Style enumerator representing an underline escape code.
@@ -187,15 +194,16 @@ Generic interface to turn a style, foreground or background enumerator into an a
187
194
188
195
# ### Syntax
189
196
190
- ` string = [[stdlib_string_colors(module):to_string(interface)]] (enum )`
197
+ ` string = [[stdlib_string_colors(module):to_string(interface)]] (code )`
191
198
192
199
# ### Class
193
200
194
201
Pure function.
195
202
196
203
# ### Argument
197
204
198
- ``enum`` : Style, foreground or background enumerator, this argument is ``intent(in)``.
205
+ ``code`` : Style, foreground or background code of ``ansi_color`` type,
206
+ this argument is ``intent(in)``.
199
207
200
208
# ### Result value
201
209
@@ -205,27 +213,92 @@ The result is a default character string.
205
213
206
214
Experimental
207
215
216
+ # ### Example
208
217
209
- # ## ``to_string``
218
+ ` ` ` fortran
219
+ program demo_string
220
+ use stdlib_terminal_colors, only : fg_color_green, style_reset, to_string
221
+ implicit none
210
222
211
- Generic interface to turn a foreground or background true color type into an actual escape code string for printout.
223
+ print '(a)', to_string(fg_color_green) // "Colorized text message" // to_string(style_reset)
224
+ end program demo_string
225
+ ` ` `
226
+
227
+
228
+ # ## ``operator(+)``
229
+
230
+ Add two escape sequences, attributes in the right value override the left value ones.
212
231
213
232
# ### Syntax
214
233
215
- ` string = [[stdlib_string_colors(module):to_string(interface)]] (color24) `
234
+ ` code = lval + rval `
216
235
217
236
# ### Class
218
237
219
238
Pure function.
220
239
221
240
# ### Argument
222
241
223
- ``color24`` : Foreground or background true color instance, this argument is ``intent(in)``.
242
+ ``lval`` : Style, foreground or background code of ``ansi_color`` type,
243
+ this argument is ``intent(in)``.
244
+ ``rval`` : Style, foreground or background code of ``ansi_color`` type,
245
+ this argument is ``intent(in)``.
224
246
225
247
# ### Result value
226
248
227
- The result is a default character string .
249
+ The result is a style, foreground or background code of ``ansi_color`` type .
228
250
229
251
# ### Status
230
252
231
253
Experimental
254
+
255
+ # ### Example
256
+
257
+ ` ` ` fortran
258
+ program demo_combine
259
+ use stdlib_terminal_colors, only : fg_color_red, style_bold, ansi_color
260
+ implicit none
261
+ type(ansi_color) :: bold_red
262
+
263
+ bold_red = fg_color_red + style_bold
264
+ end program demo_combine
265
+ ` ` `
266
+
267
+
268
+ # ## ``operator(//)``
269
+
270
+ Concatenate an escape code with a string and turn it into an actual escape sequence
271
+
272
+ # ### Syntax
273
+
274
+ ` code = lval + rval`
275
+
276
+ # ### Class
277
+
278
+ Pure function.
279
+
280
+ # ### Argument
281
+
282
+ ``lval`` : Style, foreground or background code of ``ansi_color`` type or a character string,
283
+ this argument is ``intent(in)``.
284
+ ``rval`` : Style, foreground or background code of ``ansi_color`` type or a character string,
285
+ this argument is ``intent(in)``.
286
+
287
+ # ### Result value
288
+
289
+ The result is a character string with the escape sequence prepended or appended.
290
+
291
+ # ### Status
292
+
293
+ Experimental
294
+
295
+ # ### Example
296
+
297
+ ` ` ` fortran
298
+ program demo_concat
299
+ use stdlib_terminal_colors, only : fg_color_red, style_reset, operator(//)
300
+ implicit none
301
+
302
+ print '(a)', fg_color_red // "Colorized text message" // style_reset
303
+ end program demo_concat
304
+ ` ` `
0 commit comments