stdlib_ansi Module

Terminal color and style escape sequences



Variables

Type Visibility Attributes Name Initial
type(ansi_code), public, parameter :: bg_color_black = ansi_code(bg=0)

Identifier for black background color

type(ansi_code), public, parameter :: bg_color_blue = ansi_code(bg=4)

Identifier for blue background color

type(ansi_code), public, parameter :: bg_color_cyan = ansi_code(bg=6)

Identifier for cyan background color

type(ansi_code), public, parameter :: bg_color_default = ansi_code(bg=9)

Identifier for the default background color

type(ansi_code), public, parameter :: bg_color_green = ansi_code(bg=2)

Identifier for green background color

type(ansi_code), public, parameter :: bg_color_magenta = ansi_code(bg=5)

Identifier for magenta background color

type(ansi_code), public, parameter :: bg_color_red = ansi_code(bg=1)

Identifier for red background color

type(ansi_code), public, parameter :: bg_color_white = ansi_code(bg=7)

Identifier for white background color

type(ansi_code), public, parameter :: bg_color_yellow = ansi_code(bg=3)

Identifier for yellow background color

type(ansi_code), public, parameter :: fg_color_black = ansi_code(fg=0)

Identifier for black foreground color

type(ansi_code), public, parameter :: fg_color_blue = ansi_code(fg=4)

Identifier for blue foreground color

type(ansi_code), public, parameter :: fg_color_cyan = ansi_code(fg=6)

Identifier for cyan foreground color

type(ansi_code), public, parameter :: fg_color_default = ansi_code(fg=9)

Identifier for the default foreground color

type(ansi_code), public, parameter :: fg_color_green = ansi_code(fg=2)

Identifier for green foreground color

type(ansi_code), public, parameter :: fg_color_magenta = ansi_code(fg=5)

Identifier for magenta foreground color

type(ansi_code), public, parameter :: fg_color_red = ansi_code(fg=1)

Identifier for red foreground color

type(ansi_code), public, parameter :: fg_color_white = ansi_code(fg=7)

Identifier for white foreground color

type(ansi_code), public, parameter :: fg_color_yellow = ansi_code(fg=3)

Identifier for yellow foreground color

type(ansi_code), public, parameter :: style_blink = ansi_code(style=5)

Identifier for blink style

type(ansi_code), public, parameter :: style_blink_fast = ansi_code(style=6)

Identifier for (fast) blink style

type(ansi_code), public, parameter :: style_bold = ansi_code(style=1)

Identifier for bold style

type(ansi_code), public, parameter :: style_dim = ansi_code(style=2)

Identifier for dim style

type(ansi_code), public, parameter :: style_hidden = ansi_code(style=8)

Identifier for hidden style

type(ansi_code), public, parameter :: style_italic = ansi_code(style=3)

Identifier for italic style

type(ansi_code), public, parameter :: style_reset = ansi_code(style=0)

Identifier for reset style

type(ansi_code), public, parameter :: style_reverse = ansi_code(style=7)

Identifier for reverse style

type(ansi_code), public, parameter :: style_strikethrough = ansi_code(style=9)

Identifier for strikethrough style

type(ansi_code), public, parameter :: style_underline = ansi_code(style=4)

Identifier for underline style


Interfaces

public interface operator(+)

  • private pure module function add(lval, rval) result(code)

    Add two escape sequences, attributes in the right value override the left value ones.

    Arguments

    Type IntentOptional Attributes Name
    type(ansi_code), intent(in) :: lval

    First escape code

    type(ansi_code), intent(in) :: rval

    Second escape code

    Return Value type(ansi_code)

    Combined escape code

public interface operator(//)

  • private pure module function concat_left(lval, code) result(str)

    Concatenate an escape code with a string and turn it into an actual escape sequence

    Arguments

    Type IntentOptional Attributes Name
    character(len=*), intent(in) :: lval

    String to add the escape code to

    type(ansi_code), intent(in) :: code

    Escape sequence

    Return Value character(len=:), allocatable

    Concatenated string

  • private pure module function concat_left_str(lval, code) result(str)

    Concatenate an escape code with a string and turn it into an actual escape sequence

    Arguments

    Type IntentOptional Attributes Name
    type(string_type), intent(in) :: lval

    String to add the escape code to

    type(ansi_code), intent(in) :: code

    Escape sequence

    Return Value type(string_type)

    Concatenated string

  • private pure module function concat_right(code, rval) result(str)

    Concatenate an escape code with a string and turn it into an actual escape sequence

    Arguments

    Type IntentOptional Attributes Name
    type(ansi_code), intent(in) :: code

    Escape sequence

    character(len=*), intent(in) :: rval

    String to add the escape code to

    Return Value character(len=:), allocatable

    Concatenated string

  • private pure module function concat_right_str(code, rval) result(str)

    Concatenate an escape code with a string and turn it into an actual escape sequence

    Arguments

    Type IntentOptional Attributes Name
    type(ansi_code), intent(in) :: code

    Escape sequence

    type(string_type), intent(in) :: rval

    String to add the escape code to

    Return Value type(string_type)

    Concatenated string

public interface to_string

  • private pure module function to_string_ansi_code(code) result(str)

    Transform a color code into an actual ANSI escape sequence

    Arguments

    Type IntentOptional Attributes Name
    type(ansi_code), intent(in) :: code

    Color code to be used

    Return Value character(len=:), allocatable

    ANSI escape sequence representing the color code


Derived Types

type, public ::  ansi_code

Container for terminal escape code