Implementation of a terminal to provide ANSI escape sequences
ANSI escape codes for producing terminal colors. The ansi_code
derived
type is used to store ANSI escape codes and can be combined with other
codes or applied to strings by concatenation. The default or uninitialized
ansi_code
is a stub and does not produce escape sequences when applied
to a string.
Available colors are
color | foreground | background |
---|---|---|
black | black (30) |
bg_black (40) |
red | red (31) |
bg_red (41) |
green | green (32) |
bg_green (42) |
yellow | yellow (33) |
bg_yellow (43) |
blue | blue (34) |
bg_blue (44) |
magenta | magenta (35) |
bg_magenta (45) |
cyan | cyan (36) |
bg_cyan (46) |
white | white (37) |
bg_white (47) |
gray | gray (90) |
bg_gray (100) |
bright red | bright_red (91) |
bg_bright_red (101) |
bright green | bright_green (92) |
bg_bright_green (102) |
bright yellow | bright_yellow (93) |
bg_bright_yellow (103) |
bright blue | bright_blue (94) |
bg_bright_blue (104) |
bright magenta | bright_magenta (95) |
bg_bright_magenta (105) |
bright cyan | bright_cyan (96) |
bg_bright_cyan (106) |
bright white | bright_white (97) |
bg_bright_white (107) |
Available styles are
style |
------------| ---------------
reset | reset
(0)
bold | bold
(1)
dim | dim
(2)
italic | italic
(3)
underline | underline
(4)
blink | blink
(5)
blink rapid | blink_rapid
(6)
reverse | reverse
(7)
hidden | hidden
(8)
crossed | crossed
(9)
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
type(ansi_code), | public, | parameter | :: | bg_black | = | ansi_code(bg=40_i1) | |
type(ansi_code), | public, | parameter | :: | bg_blue | = | ansi_code(bg=44_i1) | |
type(ansi_code), | public, | parameter | :: | bg_bright_blue | = | ansi_code(bg=104_i1) | |
type(ansi_code), | public, | parameter | :: | bg_bright_cyan | = | ansi_code(bg=106_i1) | |
type(ansi_code), | public, | parameter | :: | bg_bright_green | = | ansi_code(bg=102_i1) | |
type(ansi_code), | public, | parameter | :: | bg_bright_magenta | = | ansi_code(bg=105_i1) | |
type(ansi_code), | public, | parameter | :: | bg_bright_red | = | ansi_code(bg=101_i1) | |
type(ansi_code), | public, | parameter | :: | bg_bright_white | = | ansi_code(bg=107_i1) | |
type(ansi_code), | public, | parameter | :: | bg_bright_yellow | = | ansi_code(bg=103_i1) | |
type(ansi_code), | public, | parameter | :: | bg_cyan | = | ansi_code(bg=46_i1) | |
type(ansi_code), | public, | parameter | :: | bg_gray | = | ansi_code(bg=100_i1) | |
type(ansi_code), | public, | parameter | :: | bg_green | = | ansi_code(bg=42_i1) | |
type(ansi_code), | public, | parameter | :: | bg_magenta | = | ansi_code(bg=45_i1) | |
type(ansi_code), | public, | parameter | :: | bg_red | = | ansi_code(bg=41_i1) | |
type(ansi_code), | public, | parameter | :: | bg_white | = | ansi_code(bg=47_i1) | |
type(ansi_code), | public, | parameter | :: | bg_yellow | = | ansi_code(bg=43_i1) | |
type(ansi_code), | public, | parameter | :: | black | = | ansi_code(fg=30_i1) | |
type(ansi_code), | public, | parameter | :: | blink | = | ansi_code(style=5_i1) | |
type(ansi_code), | public, | parameter | :: | blink_rapid | = | ansi_code(style=6_i1) | |
type(ansi_code), | public, | parameter | :: | blue | = | ansi_code(fg=34_i1) | |
type(ansi_code), | public, | parameter | :: | bold | = | ansi_code(style=1_i1) | |
type(ansi_code), | public, | parameter | :: | bright_blue | = | ansi_code(fg=94_i1) | |
type(ansi_code), | public, | parameter | :: | bright_cyan | = | ansi_code(fg=96_i1) | |
type(ansi_code), | public, | parameter | :: | bright_green | = | ansi_code(fg=92_i1) | |
type(ansi_code), | public, | parameter | :: | bright_magenta | = | ansi_code(fg=95_i1) | |
type(ansi_code), | public, | parameter | :: | bright_red | = | ansi_code(fg=91_i1) | |
type(ansi_code), | public, | parameter | :: | bright_white | = | ansi_code(fg=97_i1) | |
type(ansi_code), | public, | parameter | :: | bright_yellow | = | ansi_code(fg=93_i1) | |
type(ansi_code), | public, | parameter | :: | crossed | = | ansi_code(style=9_i1) | |
type(ansi_code), | public, | parameter | :: | cyan | = | ansi_code(fg=36_i1) | |
type(ansi_code), | public, | parameter | :: | dim | = | ansi_code(style=2_i1) | |
type(ansi_code), | public, | parameter | :: | gray | = | ansi_code(fg=90_i1) | |
type(ansi_code), | public, | parameter | :: | green | = | ansi_code(fg=32_i1) | |
type(ansi_code), | public, | parameter | :: | hidden | = | ansi_code(style=8_i1) | |
type(ansi_code), | public, | parameter | :: | italic | = | ansi_code(style=3_i1) | |
type(ansi_code), | public, | parameter | :: | magenta | = | ansi_code(fg=35_i1) | |
type(ansi_code), | public, | parameter | :: | red | = | ansi_code(fg=31_i1) | |
type(ansi_code), | public, | parameter | :: | reset | = | ansi_code(style=0_i1) | |
type(ansi_code), | public, | parameter | :: | reverse | = | ansi_code(style=7_i1) | |
type(ansi_code), | public, | parameter | :: | underline | = | ansi_code(style=4_i1) | |
type(ansi_code), | public, | parameter | :: | white | = | ansi_code(fg=37_i1) | |
type(ansi_code), | public, | parameter | :: | yellow | = | ansi_code(fg=33_i1) |
Add two escape sequences, attributes in the right value override the left value ones.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(ansi_code), | intent(in) | :: | lval |
First escape code |
||
type(ansi_code), | intent(in) | :: | rval |
Second escape code |
Combined escape code
Concatenate an escape code with a string and turn it into an actual escape sequence
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | lval |
String to add the escape code to |
||
type(ansi_code), | intent(in) | :: | code |
Escape sequence |
Concatenated string
Concatenate an escape code with a string and turn it into an actual escape sequence
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(ansi_code), | intent(in) | :: | code |
Escape sequence |
||
character(len=*), | intent(in) | :: | rval |
String to add the escape code to |
Concatenated string
Constructor to create new terminal
Create new terminal
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
logical, | intent(in) | :: | use_color |
Enable color support in terminal |
New terminal instance
Container for terminal escape code
Terminal wrapper to handle color escape sequences, must be initialized with color support to provide colorful output. Default and uninitialized instances will remain usable but provide only stubs and do not produce colorful output. This behavior is useful for creating applications which can toggle color support.
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
type(ansi_code), | public | :: | bg_black | = | ansi_code() | ||
type(ansi_code), | public | :: | bg_blue | = | ansi_code() | ||
type(ansi_code), | public | :: | bg_bright_blue | = | ansi_code() | ||
type(ansi_code), | public | :: | bg_bright_cyan | = | ansi_code() | ||
type(ansi_code), | public | :: | bg_bright_green | = | ansi_code() | ||
type(ansi_code), | public | :: | bg_bright_magenta | = | ansi_code() | ||
type(ansi_code), | public | :: | bg_bright_red | = | ansi_code() | ||
type(ansi_code), | public | :: | bg_bright_white | = | ansi_code() | ||
type(ansi_code), | public | :: | bg_bright_yellow | = | ansi_code() | ||
type(ansi_code), | public | :: | bg_cyan | = | ansi_code() | ||
type(ansi_code), | public | :: | bg_gray | = | ansi_code() | ||
type(ansi_code), | public | :: | bg_green | = | ansi_code() | ||
type(ansi_code), | public | :: | bg_magenta | = | ansi_code() | ||
type(ansi_code), | public | :: | bg_red | = | ansi_code() | ||
type(ansi_code), | public | :: | bg_white | = | ansi_code() | ||
type(ansi_code), | public | :: | bg_yellow | = | ansi_code() | ||
type(ansi_code), | public | :: | black | = | ansi_code() | ||
type(ansi_code), | public | :: | blink | = | ansi_code() | ||
type(ansi_code), | public | :: | blink_rapid | = | ansi_code() | ||
type(ansi_code), | public | :: | blue | = | ansi_code() | ||
type(ansi_code), | public | :: | bold | = | ansi_code() | ||
type(ansi_code), | public | :: | bright_blue | = | ansi_code() | ||
type(ansi_code), | public | :: | bright_cyan | = | ansi_code() | ||
type(ansi_code), | public | :: | bright_green | = | ansi_code() | ||
type(ansi_code), | public | :: | bright_magenta | = | ansi_code() | ||
type(ansi_code), | public | :: | bright_red | = | ansi_code() | ||
type(ansi_code), | public | :: | bright_white | = | ansi_code() | ||
type(ansi_code), | public | :: | bright_yellow | = | ansi_code() | ||
type(ansi_code), | public | :: | crossed | = | ansi_code() | ||
type(ansi_code), | public | :: | cyan | = | ansi_code() | ||
type(ansi_code), | public | :: | dim | = | ansi_code() | ||
type(ansi_code), | public | :: | gray | = | ansi_code() | ||
type(ansi_code), | public | :: | green | = | ansi_code() | ||
type(ansi_code), | public | :: | hidden | = | ansi_code() | ||
type(ansi_code), | public | :: | italic | = | ansi_code() | ||
type(ansi_code), | public | :: | magenta | = | ansi_code() | ||
type(ansi_code), | public | :: | red | = | ansi_code() | ||
type(ansi_code), | public | :: | reset | = | ansi_code() | ||
type(ansi_code), | public | :: | reverse | = | ansi_code() | ||
type(ansi_code), | public | :: | underline | = | ansi_code() | ||
type(ansi_code), | public | :: | white | = | ansi_code() | ||
type(ansi_code), | public | :: | yellow | = | ansi_code() |
Constructor to create new terminal
private pure function new_terminal (use_color) | Create new terminal |
Transform a color code into an actual ANSI escape sequence
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(ansi_code), | intent(in) | :: | code |
Color code to be used |
ANSI escape sequence representing the color code