proc getColour {colour {background False}} { set colourArr(black) "0;30" set colourArr(blue) "0;34" set colourArr(blueLight) "1;34" set colourArr(brown) "0;33" set colourArr(cyan) "0;36" set colourArr(cyanLight) "1;36" set colourArr(grayDark) "1;30" set colourArr(grayLight) "0;37" set colourArr(green) "0;32" set colourArr(greenLight) "1;32" set colourArr(nothing) "0" set colourArr(purple) "0;35" set colourArr(purpleLight) "1;35" set colourArr(red) "0;31" set colourArr(redLight) "1;31" set colourArr(white) "1;37" set colourArr(yellow) "1;33" set colourEnd "m\002" set colourStart "\001\033\[" if {$colour eq "names"} { return [lsort [array names colourArr]] } if {! [info exist colourArr($colour)]} { error [format "ERROR: %s got a non existing colour (%s)" \ [getProcName] $colour] } set colourCode $colourArr($colour) # No need to check for nothing, replace out of range does nothing. if {$background} { set colourCode [string replace $colourCode 2 2 4] } return "$colourStart$colourCode$colourEnd" }With names you get a list of defined colours. When given a non-existing colour an error is generated. A background colour has at index 2 a 4 instead of a 3.
As always: comments, tips and questions are appreciated.bll 2018-6-6 Octal specifications with a leading zero will go away: https://core.tcl.tk/tips/doc/trunk/tip/114.md


ak - 2018-06-06 19:43:17Hi bll I am not sure what the removal of octal interpretation for "08" etc. in expressions has to do with the terminal color codes ?! If you are looking at the "\0..." escapes, these are backslash substitutions for characters, under rule 9 of the Dodekalogue, and are not affected by the TIP, at all. The TIP is about numbers in expressions, nothing else. It will not affect "file permissions", nor the backslash substitutions.bll Ok, thanks for the clarification.