Skip to content

Commit fd319ca

Browse files
awvwgk14NGiestas
andcommitted
Rename to ansi_code, initialize components
Co-authored-by: Ian Giestas Pauli <[email protected]>
1 parent ef972d2 commit fd319ca

4 files changed

+63
-64
lines changed

doc/specs/stdlib_terminal_color.md

+12-12
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ Support terminal escape sequences to produce styled and colored terminal output.
1515
## Derived types provided
1616

1717

18-
### ``ansi_color`` type
18+
### ``ansi_code`` type
1919

20-
The ``ansi_color`` type represent an ANSI escape sequence with a style, forground
20+
The ``ansi_code`` type represent an ANSI escape sequence with a style, forground
2121
color and background color attribute. By default the instances of this type are
2222
empty and represent no escape sequence.
2323

@@ -29,10 +29,10 @@ Experimental
2929

3030
```fortran
3131
program demo_color
32-
use stdlib_terminal_colors, only : fg_color_blue, style_bold, style_reset, ansi_color, &
32+
use stdlib_terminal_colors, only : fg_color_blue, style_bold, style_reset, ansi_code, &
3333
& operator(//), operator(+)
3434
implicit none
35-
type(ansi_color) :: highlight, reset
35+
type(ansi_code) :: highlight, reset
3636
3737
print '(a)', highlight // "Dull text message" // reset
3838
@@ -202,7 +202,7 @@ Pure function.
202202

203203
#### Argument
204204

205-
``code``: Style, foreground or background code of ``ansi_color`` type,
205+
``code``: Style, foreground or background code of ``ansi_code`` type,
206206
this argument is ``intent(in)``.
207207

208208
#### Result value
@@ -239,14 +239,14 @@ Pure function.
239239

240240
#### Argument
241241

242-
``lval``: Style, foreground or background code of ``ansi_color`` type,
242+
``lval``: Style, foreground or background code of ``ansi_code`` type,
243243
this argument is ``intent(in)``.
244-
``rval``: Style, foreground or background code of ``ansi_color`` type,
244+
``rval``: Style, foreground or background code of ``ansi_code`` type,
245245
this argument is ``intent(in)``.
246246

247247
#### Result value
248248

249-
The result is a style, foreground or background code of ``ansi_color`` type.
249+
The result is a style, foreground or background code of ``ansi_code`` type.
250250

251251
#### Status
252252

@@ -256,9 +256,9 @@ Experimental
256256

257257
```fortran
258258
program demo_combine
259-
use stdlib_terminal_colors, only : fg_color_red, style_bold, ansi_color
259+
use stdlib_terminal_colors, only : fg_color_red, style_bold, ansi_code
260260
implicit none
261-
type(ansi_color) :: bold_red
261+
type(ansi_code) :: bold_red
262262
263263
bold_red = fg_color_red + style_bold
264264
end program demo_combine
@@ -279,9 +279,9 @@ Pure function.
279279

280280
#### Argument
281281

282-
``lval``: Style, foreground or background code of ``ansi_color`` type or a character string,
282+
``lval``: Style, foreground or background code of ``ansi_code`` type or a character string,
283283
this argument is ``intent(in)``.
284-
``rval``: Style, foreground or background code of ``ansi_color`` type or a character string,
284+
``rval``: Style, foreground or background code of ``ansi_code`` type or a character string,
285285
this argument is ``intent(in)``.
286286

287287
#### Result value

src/stdlib_terminal_colors.f90

+39-39
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module stdlib_terminal_colors
66
implicit none
77
private
88

9-
public :: ansi_color
9+
public :: ansi_code
1010
public :: style_reset, style_bold, style_dim, style_italic, style_underline, &
1111
& style_blink, style_blink_fast, style_reverse, style_hidden, style_strikethrough
1212
public :: fg_color_black, fg_color_red, fg_color_green, fg_color_yellow, fg_color_blue, &
@@ -19,97 +19,97 @@ module stdlib_terminal_colors
1919

2020

2121
!> Container for terminal escape code
22-
type :: ansi_color
22+
type :: ansi_code
2323
private
2424
!> Style descriptor
2525
integer(i1) :: style = -1_i1
2626
!> Background color descriptor
2727
integer(i1) :: bg = -1_i1
2828
!> Foreground color descriptor
2929
integer(i1) :: fg = -1_i1
30-
end type ansi_color
30+
end type ansi_code
3131

3232

3333
!> Identifier for reset style
34-
type(ansi_color), parameter :: style_reset = ansi_color(style=0)
34+
type(ansi_code), parameter :: style_reset = ansi_code(style=0)
3535
!> Identifier for bold style
36-
type(ansi_color), parameter :: style_bold = ansi_color(style=1)
36+
type(ansi_code), parameter :: style_bold = ansi_code(style=1)
3737
!> Identifier for dim style
38-
type(ansi_color), parameter :: style_dim = ansi_color(style=2)
38+
type(ansi_code), parameter :: style_dim = ansi_code(style=2)
3939
!> Identifier for italic style
40-
type(ansi_color), parameter :: style_italic = ansi_color(style=3)
40+
type(ansi_code), parameter :: style_italic = ansi_code(style=3)
4141
!> Identifier for underline style
42-
type(ansi_color), parameter :: style_underline = ansi_color(style=4)
42+
type(ansi_code), parameter :: style_underline = ansi_code(style=4)
4343
!> Identifier for blink style
44-
type(ansi_color), parameter :: style_blink = ansi_color(style=5)
44+
type(ansi_code), parameter :: style_blink = ansi_code(style=5)
4545
!> Identifier for (fast) blink style
46-
type(ansi_color), parameter :: style_blink_fast = ansi_color(style=6)
46+
type(ansi_code), parameter :: style_blink_fast = ansi_code(style=6)
4747
!> Identifier for reverse style
48-
type(ansi_color), parameter :: style_reverse = ansi_color(style=7)
48+
type(ansi_code), parameter :: style_reverse = ansi_code(style=7)
4949
!> Identifier for hidden style
50-
type(ansi_color), parameter :: style_hidden = ansi_color(style=8)
50+
type(ansi_code), parameter :: style_hidden = ansi_code(style=8)
5151
!> Identifier for strikethrough style
52-
type(ansi_color), parameter :: style_strikethrough = ansi_color(style=9)
52+
type(ansi_code), parameter :: style_strikethrough = ansi_code(style=9)
5353

5454
!> Identifier for black foreground color
55-
type(ansi_color), parameter :: fg_color_black = ansi_color(fg=0)
55+
type(ansi_code), parameter :: fg_color_black = ansi_code(fg=0)
5656
!> Identifier for red foreground color
57-
type(ansi_color), parameter :: fg_color_red = ansi_color(fg=1)
57+
type(ansi_code), parameter :: fg_color_red = ansi_code(fg=1)
5858
!> Identifier for green foreground color
59-
type(ansi_color), parameter :: fg_color_green = ansi_color(fg=2)
59+
type(ansi_code), parameter :: fg_color_green = ansi_code(fg=2)
6060
!> Identifier for yellow foreground color
61-
type(ansi_color), parameter :: fg_color_yellow = ansi_color(fg=3)
61+
type(ansi_code), parameter :: fg_color_yellow = ansi_code(fg=3)
6262
!> Identifier for blue foreground color
63-
type(ansi_color), parameter :: fg_color_blue = ansi_color(fg=4)
63+
type(ansi_code), parameter :: fg_color_blue = ansi_code(fg=4)
6464
!> Identifier for magenta foreground color
65-
type(ansi_color), parameter :: fg_color_magenta = ansi_color(fg=5)
65+
type(ansi_code), parameter :: fg_color_magenta = ansi_code(fg=5)
6666
!> Identifier for cyan foreground color
67-
type(ansi_color), parameter :: fg_color_cyan = ansi_color(fg=6)
67+
type(ansi_code), parameter :: fg_color_cyan = ansi_code(fg=6)
6868
!> Identifier for white foreground color
69-
type(ansi_color), parameter :: fg_color_white = ansi_color(fg=7)
69+
type(ansi_code), parameter :: fg_color_white = ansi_code(fg=7)
7070
!> Identifier for the default foreground color
71-
type(ansi_color), parameter :: fg_color_default = ansi_color(fg=9)
71+
type(ansi_code), parameter :: fg_color_default = ansi_code(fg=9)
7272

7373
!> Identifier for black background color
74-
type(ansi_color), parameter :: bg_color_black = ansi_color(bg=0)
74+
type(ansi_code), parameter :: bg_color_black = ansi_code(bg=0)
7575
!> Identifier for red background color
76-
type(ansi_color), parameter :: bg_color_red = ansi_color(bg=1)
76+
type(ansi_code), parameter :: bg_color_red = ansi_code(bg=1)
7777
!> Identifier for green background color
78-
type(ansi_color), parameter :: bg_color_green = ansi_color(bg=2)
78+
type(ansi_code), parameter :: bg_color_green = ansi_code(bg=2)
7979
!> Identifier for yellow background color
80-
type(ansi_color), parameter :: bg_color_yellow = ansi_color(bg=3)
80+
type(ansi_code), parameter :: bg_color_yellow = ansi_code(bg=3)
8181
!> Identifier for blue background color
82-
type(ansi_color), parameter :: bg_color_blue = ansi_color(bg=4)
82+
type(ansi_code), parameter :: bg_color_blue = ansi_code(bg=4)
8383
!> Identifier for magenta background color
84-
type(ansi_color), parameter :: bg_color_magenta = ansi_color(bg=5)
84+
type(ansi_code), parameter :: bg_color_magenta = ansi_code(bg=5)
8585
!> Identifier for cyan background color
86-
type(ansi_color), parameter :: bg_color_cyan = ansi_color(bg=6)
86+
type(ansi_code), parameter :: bg_color_cyan = ansi_code(bg=6)
8787
!> Identifier for white background color
88-
type(ansi_color), parameter :: bg_color_white = ansi_color(bg=7)
88+
type(ansi_code), parameter :: bg_color_white = ansi_code(bg=7)
8989
!> Identifier for the default background color
90-
type(ansi_color), parameter :: bg_color_default = ansi_color(bg=9)
90+
type(ansi_code), parameter :: bg_color_default = ansi_code(bg=9)
9191

9292

9393
interface to_string
9494
!> Transform a color code into an actual ANSI escape sequence
95-
pure module function to_string_ansi_color(code) result(str)
95+
pure module function to_string_ansi_code(code) result(str)
9696
!> Color code to be used
97-
type(ansi_color), intent(in) :: code
97+
type(ansi_code), intent(in) :: code
9898
!> ANSI escape sequence representing the color code
9999
character(len=:), allocatable :: str
100-
end function to_string_ansi_color
100+
end function to_string_ansi_code
101101
end interface to_string
102102

103103

104104
interface operator(+)
105105
!> Add two escape sequences, attributes in the right value override the left value ones.
106106
pure module function add(lval, rval) result(code)
107107
!> First escape code
108-
type(ansi_color), intent(in) :: lval
108+
type(ansi_code), intent(in) :: lval
109109
!> Second escape code
110-
type(ansi_color), intent(in) :: rval
110+
type(ansi_code), intent(in) :: rval
111111
!> Combined escape code
112-
type(ansi_color) :: code
112+
type(ansi_code) :: code
113113
end function add
114114
end interface operator(+)
115115

@@ -119,7 +119,7 @@ pure module function concat_left(lval, code) result(str)
119119
!> String to add the escape code to
120120
character(len=*), intent(in) :: lval
121121
!> Escape sequence
122-
type(ansi_color), intent(in) :: code
122+
type(ansi_code), intent(in) :: code
123123
!> Concatenated string
124124
character(len=:), allocatable :: str
125125
end function concat_left
@@ -129,7 +129,7 @@ pure module function concat_right(code, rval) result(str)
129129
!> String to add the escape code to
130130
character(len=*), intent(in) :: rval
131131
!> Escape sequence
132-
type(ansi_color), intent(in) :: code
132+
type(ansi_code), intent(in) :: code
133133
!> Concatenated string
134134
character(len=:), allocatable :: str
135135
end function concat_right

src/stdlib_terminal_colors_operator.f90

+8-9
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,23 @@
99
!> Add two escape sequences, attributes in the right value override the left value ones.
1010
pure module function add(lval, rval) result(code)
1111
!> First escape code
12-
type(ansi_color), intent(in) :: lval
12+
type(ansi_code), intent(in) :: lval
1313
!> Second escape code
14-
type(ansi_color), intent(in) :: rval
14+
type(ansi_code), intent(in) :: rval
1515
!> Combined escape code
16-
type(ansi_color) :: code
16+
type(ansi_code) :: code
1717

18-
code = ansi_color( &
19-
style=merge(rval%style, lval%style, rval%style >= 0), &
20-
fg=merge(rval%fg, lval%fg, rval%fg >= 0), &
21-
bg=merge(rval%bg, lval%bg, rval%bg >= 0))
18+
code%style = merge(rval%style, lval%style, rval%style >= 0)
19+
code%fg = merge(rval%fg, lval%fg, rval%fg >= 0)
20+
code%bg = merge(rval%bg, lval%bg, rval%bg >= 0)
2221
end function add
2322

2423
!> Concatenate an escape code with a string and turn it into an actual escape sequence
2524
pure module function concat_left(lval, code) result(str)
2625
!> String to add the escape code to
2726
character(len=*), intent(in) :: lval
2827
!> Escape sequence
29-
type(ansi_color), intent(in) :: code
28+
type(ansi_code), intent(in) :: code
3029
!> Concatenated string
3130
character(len=:), allocatable :: str
3231

@@ -38,7 +37,7 @@ pure module function concat_right(code, rval) result(str)
3837
!> String to add the escape code to
3938
character(len=*), intent(in) :: rval
4039
!> Escape sequence
41-
type(ansi_color), intent(in) :: code
40+
type(ansi_code), intent(in) :: code
4241
!> Concatenated string
4342
character(len=:), allocatable :: str
4443

src/stdlib_terminal_colors_to_string.f90

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
contains
1111

1212
!> Transform a color code into an actual ANSI escape sequence
13-
pure module function to_string_ansi_color(code) result(str)
13+
pure module function to_string_ansi_code(code) result(str)
1414
!> Color code to be used
15-
type(ansi_color), intent(in) :: code
15+
type(ansi_code), intent(in) :: code
1616
!> ANSI escape sequence representing the color code
1717
character(len=:), allocatable :: str
1818

@@ -25,12 +25,12 @@ pure module function to_string_ansi_color(code) result(str)
2525
else
2626
str = ""
2727
end if
28-
end function to_string_ansi_color
28+
end function to_string_ansi_code
2929

3030
!> Check whether the code describes any color or is just a stub
3131
pure function anycolor(code)
3232
!> Escape sequence
33-
type(ansi_color), intent(in) :: code
33+
type(ansi_code), intent(in) :: code
3434
!> Any color / style is active
3535
logical :: anycolor
3636

0 commit comments

Comments
 (0)