Skip to content

Commit 4128e77

Browse files
committed
Add terminal and color escape sequences
- style, foreground and background color enumerators - true color (24-bit) types - generation of escape strings via to_string function
1 parent 57c41f9 commit 4128e77

File tree

6 files changed

+494
-0
lines changed

6 files changed

+494
-0
lines changed

doc/specs/index.md

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ This is and index/directory of the specifications (specs) for each new module/fe
1313

1414
- [ascii](./stdlib_ascii.html) - Procedures for handling ASCII characters
1515
- [bitsets](./stdlib_bitsets.html) - Bitset data types and procedures
16+
- [colors](./stdlib_colors.html) - Terminal color and style escape sequences
1617
- [error](./stdlib_error.html) - Catching and handling errors
1718
- [IO](./stdlib_io.html) - Input/output helper & convenience
1819
- [kinds](./stdlib_kinds.html) - Kind parameters

doc/specs/stdlib_color.md

+231
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
---
2+
title: terminal colors
3+
...
4+
5+
6+
# The `stdlib_colors` module
7+
8+
[TOC]
9+
10+
## Introduction
11+
12+
Support terminal escape sequences to produce styled and colored terminal output.
13+
14+
15+
## Derived types provided
16+
17+
18+
### ``fg_color24`` type
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.
22+
23+
#### Status
24+
25+
Experimental
26+
27+
28+
### ``bg_color24`` type
29+
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.
32+
33+
#### Status
34+
35+
Experimental
36+
37+
38+
## Constants provided
39+
40+
### ``style_reset``
41+
42+
Style enumerator representing a reset escape code.
43+
44+
45+
### ``style_bold``
46+
47+
Style enumerator representing a bold escape code.
48+
49+
50+
### ``style_dim``
51+
52+
Style enumerator representing a dim escape code.
53+
54+
55+
56+
### ``style_italic``
57+
58+
Style enumerator representing an italic escape code.
59+
60+
61+
62+
### ``style_underline``
63+
64+
Style enumerator representing an underline escape code.
65+
66+
67+
### ``style_blink``
68+
69+
Style enumerator representing a blink escape code.
70+
71+
72+
### ``style_blink_fast``
73+
74+
Style enumerator representing a (fast) blink escape code.
75+
76+
77+
### ``style_reverse``
78+
79+
Style enumerator representing a reverse escape code.
80+
81+
82+
### ``style_hidden``
83+
84+
Style enumerator representing a hidden escape code.
85+
86+
87+
### ``style_strikethrough``
88+
89+
Style enumerator representing a strike-through escape code.
90+
91+
92+
### ``fg_color_black``
93+
94+
Foreground color enumerator representing a foreground black color escape code.
95+
96+
97+
### ``fg_color_red``
98+
99+
Foreground color enumerator representing a foreground red color escape code.
100+
101+
102+
### ``fg_color_green``
103+
104+
Foreground color enumerator representing a foreground green color escape code.
105+
106+
107+
### ``fg_color_yellow``
108+
109+
Foreground color enumerator representing a foreground yellow color escape code.
110+
111+
112+
### ``fg_color_blue``
113+
114+
Foreground color enumerator representing a foreground blue color escape code.
115+
116+
117+
### ``fg_color_magenta``
118+
119+
Foreground color enumerator representing a foreground magenta color escape code.
120+
121+
122+
### ``fg_color_cyan``
123+
124+
Foreground color enumerator representing a foreground cyan color escape code.
125+
126+
127+
### ``fg_color_white``
128+
129+
Foreground color enumerator representing a foreground white color escape code.
130+
131+
132+
### ``fg_color_default``
133+
134+
Foreground color enumerator representing a foreground default color escape code.
135+
136+
137+
### ``bg_color_black``
138+
139+
Background color enumerator representing a background black color escape code.
140+
141+
142+
### ``bg_color_red``
143+
144+
Background color enumerator representing a background red color escape code.
145+
146+
147+
### ``bg_color_green``
148+
149+
Background color enumerator representing a background green color escape code.
150+
151+
152+
### ``bg_color_yellow``
153+
154+
Background color enumerator representing a background yellow color escape code.
155+
156+
157+
### ``bg_color_blue``
158+
159+
Background color enumerator representing a background blue color escape code.
160+
161+
162+
### ``bg_color_magenta``
163+
164+
Background color enumerator representing a background magenta color escape code.
165+
166+
167+
### ``bg_color_cyan``
168+
169+
Background color enumerator representing a background cyan color escape code.
170+
171+
172+
### ``bg_color_white``
173+
174+
Background color enumerator representing a background white color escape code.
175+
176+
177+
### ``bg_color_default``
178+
179+
Background color enumerator representing a background default color escape code.
180+
181+
182+
## Procedures and methods provided
183+
184+
### ``to_string``
185+
186+
Generic interface to turn a style, foreground or background enumerator into an actual escape code string for printout.
187+
188+
#### Syntax
189+
190+
`string = [[stdlib_string_colors(module):to_string(interface)]] (enum)`
191+
192+
#### Class
193+
194+
Pure function.
195+
196+
#### Argument
197+
198+
``enum``: Style, foreground or background enumerator, this argument is ``intent(in)``.
199+
200+
#### Result value
201+
202+
The result is a default character string.
203+
204+
#### Status
205+
206+
Experimental
207+
208+
209+
### ``to_string``
210+
211+
Generic interface to turn a foreground or background true color type into an actual escape code string for printout.
212+
213+
#### Syntax
214+
215+
`string = [[stdlib_string_colors(module):to_string(interface)]] (color24)`
216+
217+
#### Class
218+
219+
Pure function.
220+
221+
#### Argument
222+
223+
``color24``: Foreground or background true color instance, this argument is ``intent(in)``.
224+
225+
#### Result value
226+
227+
The result is a default character string.
228+
229+
#### Status
230+
231+
Experimental

src/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ list(
6060
fypp_f90("${fyppFlags}" "${fppFiles}" outFiles)
6161

6262
set(SRC
63+
stdlib_colors.f90
64+
stdlib_colors_to_string.f90
6365
stdlib_error.f90
6466
stdlib_logger.f90
6567
stdlib_system.F90

src/Makefile.manual

+5
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ SRCFYPP = \
3838
stdlib_strings_to_string.fypp
3939

4040
SRC = f18estop.f90 \
41+
stdlib_colors.f90 \
42+
stdlib_colors_to_string.f90 \
4143
stdlib_error.f90 \
4244
stdlib_specialfunctions.f90 \
4345
stdlib_specialfunctions_legendre.f90 \
@@ -175,3 +177,6 @@ stdlib_linalg_outer_product.o: stdlib_linalg.o
175177
stdlib_stringlist_type.o: stdlib_string_type.o \
176178
stdlib_math.o \
177179
stdlib_optval.o
180+
stdlib_colors_to_string.o: \
181+
stdlib_strings.o \
182+
stdlib_colors.o

0 commit comments

Comments
 (0)