colorize_ucs4 Function

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

Arguments

TypeIntentOptionalAttributesName
character(kind=UCS4,len=*), intent(in) :: string
character(len=*), intent(in), optional :: color_fg
character(len=*), intent(in), optional :: color_bg
character(len=*), intent(in), optional :: style

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


Calls

proc~~colorize_ucs4~4~~CallsGraph proc~colorize_ucs4~4 colorize_ucs4 proc~color_index~4 color_index proc~colorize_ucs4~4->proc~color_index~4 proc~upper~6 upper proc~colorize_ucs4~4->proc~upper~6 proc~style_index~4 style_index proc~colorize_ucs4~4->proc~style_index~4

Contents

Source Code


Source Code

   pure function colorize_ucs4(string, color_fg, color_bg, style) result(colorized)
   !< Colorize and stylize strings, UCS4 kind.
   character(len=*, kind=UCS4), 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=UCS4), allocatable          :: colorized !< Colorized string.
   character(len=:, kind=UCS4), 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_ucs4