escape Function

public pure function escape(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


Source Code

pure function escape(code) result(str)
   !> Color code to be used
   type(ansi_code), intent(in) :: code
   !> ANSI escape sequence representing the color code
   character(len=:), allocatable :: str

   if (anycolor(code)) then
      str = achar(27) // "[0"  ! Always reset the style
      if (code%style > 0) str = str // ";" // to_string(code%style)
      if (code%fg >= 0) str = str // ";" // to_string(code%fg)
      if (code%bg >= 0) str = str // ";" // to_string(code%bg)
      str = str // "m"
   else
      str = ""
   end if
end function escape