colorize Function

public function colorize(s, c) result(o)

Arguments

Type IntentOptional AttributesName
character(len=*), intent(in) :: s

String to colorize

integer, , dimension(3):: c

Color code in [r,g,b] where \(r,g,b\in[0,5]\)

Return Value character(len=:), allocatable

Description

Add terminal format codes to coloize a string

Called By

proc~~colorize~~CalledByGraph proc~colorize colorize proc~showprogress showProgress proc~showprogress->proc~colorize
Help

Variables

TypeVisibility AttributesNameInitial
character(len=1), public, parameter:: CR =achar(13)
character(len=1), public, parameter:: ESC =achar(27)
character(len=20), public :: pre
character(len=3), public :: cb

Source Code

	function colorize(s,c) result(o)
		!! Add terminal format codes to coloize a string
		character(*),intent(in)::s
			!! String to colorize
		integer,dimension(3)::c ! c in [0,5]
			!! Color code in [r,g,b] where \(r,g,b\in[0,5]\)
		character(:),allocatable::o
		
		character(1),parameter::CR  = achar(13)
		character(1),parameter::ESC = achar(27)
		
		character(20)::pre
		character(3)::cb
		
		write(cb,'(1I3)') 36*c(1)+6*c(2)+c(3)+16
		pre = ESC//'[38;5;'//trim(adjustl(cb))//'m'
		o = trim(pre)//s//ESC//'[0m'
	end function colorize