Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
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]\) |
Add terminal format codes to coloize a string
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
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 |
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