Bracket a string with text to change its color on a terminal
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | s | String to colorize |
||
integer, | intent(in), | dimension(3) | :: | c | Color to use in [r,g,b] format, where \(r,b,g \in [0,5]\) |
Nodes of different colours represent the following:
Solid arrows point from a procedure to one which it calls. Dashed arrows point from an interface to procedures which implement that interface. This could include the module procedures in a generic interface or the implementation in a submodule of an interface in a parent module.
Nodes of different colours represent the following:
Solid arrows point from a procedure to one which it calls. Dashed arrows point from an interface to procedures which implement that interface. This could include the module procedures in a generic interface or the implementation in a submodule of an interface in a parent module.
function colorize(s,c) result(o)
!! Bracket a string with text to change its color on a terminal
character(*),intent(in)::s
!! String to colorize
integer,dimension(3),intent(in)::c ! c in [0,5]
!! Color to use in [r,g,b] format, where \(r,b,g \in [0,5]\)
character(:),allocatable::o
character(1),parameter::CR = achar(13)
character(1),parameter::ESC = achar(27)
character(3),parameter::post = '[0m'
character(:),allocatable::pre
pre = ESC//'[38;5;'//intToChar(36*c(1)+6*c(2)+c(3)+16)//'m'
o = trim(pre)//s//ESC//post
end function colorize