colorize_ascii Function

private pure function colorize_ascii(string, color_fg, color_bg, style) result(colorized)

Colorize and stylize strings, ASCII kind.

Arguments

Type IntentOptional Attributes Name
character(kind=ASCII, len=*), intent(in) :: string

Input string.

character(len=*), intent(in), optional :: color_fg

Foreground color definition.

character(len=*), intent(in), optional :: color_bg

Background color definition.

character(len=*), intent(in), optional :: style

Style definition.

Return Value character(kind=ASCII, len=:), allocatable

Colorized string.


Calls

proc~~colorize_ascii~~CallsGraph proc~colorize_ascii face::colorize_ascii proc~color_index face::color_index proc~colorize_ascii->proc~color_index proc~style_index face::style_index proc~colorize_ascii->proc~style_index proc~upper face::upper proc~colorize_ascii->proc~upper

Source Code

   pure function colorize_ascii(string, color_fg, color_bg, style) result(colorized)
   !< Colorize and stylize strings, ASCII kind.
   character(len=*, kind=ASCII), intent(in)           :: string    !< Input string.
   character(len=*),             intent(in), optional :: color_fg  !< Foreground color definition.
   character(len=*),             intent(in), optional :: color_bg  !< Background color definition.
   character(len=*),             intent(in), optional :: style     !< Style definition.
   character(len=:, kind=ASCII), allocatable          :: colorized !< Colorized string.
   character(len=:, kind=ASCII), allocatable          :: buffer    !< Temporary buffer.
   integer(int32)                                     :: i         !< Counter.

   colorized = string
   if (present(color_fg)) then
      i = color_index(upper(color_fg))
      if (i>0) then
         buffer = CODE_START//trim(COLORS_FG(2, i))//CODE_END
         colorized = buffer//colorized
         buffer = CODE_CLEAR
         colorized = colorized//buffer
      endif
   endif
   if (present(color_bg)) then
      i = color_index(upper(color_bg))
      if (i>0) then
         buffer = CODE_START//trim(COLORS_BG(2, i))//CODE_END
         colorized = buffer//colorized
         buffer = CODE_CLEAR
         colorized = colorized//buffer
      endif
   endif
   if (present(style)) then
      i = style_index(upper(style))
      if (i>0) then
         buffer = CODE_START//trim(STYLES(2, i))//CODE_END
         colorized = buffer//colorized
         buffer = CODE_CLEAR
         colorized = colorized//buffer
      endif
   endif
   endfunction colorize_ascii