Coloured text in MATE terminal?

Is there any way to send codes to colourize text in the MATE terminal?
For example, I might want to highlight only the word 'good' in the following sentence, by sending a code before and after 'good'..
"That was good work."
I know it can be done on a number of terminals (VT100, is one).

Yes, there are several ways:

  1. You can use ANSI escape codes directly
    ( ANSI Escape Codes · GitHub )

  2. You can also use the terminfo utility from the commandline or from a shellscript by using the command tput ( see man tput )
    Below is an overview of some colorcapabilities of tput:

Foreground color

tput setaf 0	# black
tput setaf 1	# red
tput setaf 2	# Green
tput setaf 3	# yellow
tput setaf 4	# blue
tput setaf 5	# magenta
tput setaf 6	# cyan
tput setaf 7	# white

background color

tput setab 0	# black
tput setab 1	# red
tput setab 2	# Green
tput setab 3	# yellow
tput setab 4	# blue
tput setab 5	# magenta
tput setab 6	# cyan
tput setab 7	# white

character attributes

tput bold	# bold
tput dim	# half-bright
tput sgr0	# reset to normal
tput smul	# begin underline
tput rmul	# end underline
tput rev	# reverse
tput smso	# begin standout mode (bold on rxvt)
tput rmso	# end standout mode

So you can do:

echo "That was $(tput bold)good $(tput sgr0) work."

But if you want to use it a lot , it is ofcourse highly inefficient to call tput again and again.
To optimize that I always use it like this:

B=$(tput bold)
N=$(tput sgr0)

echo "That was ${B}good${N} work."

in ANSI:

echo -e "That was\033[1m good \033[mwork."

With ANSI escape codes you can use full 8-bit per color on mate-terminal although it is beyond the capabilities of some other terminals.

try this script:


for red in {0..255..5}
	for green in {0..255..5}
		for blue in {0..255..5}
			echo -ne "\033[38;2;${red};${green};${blue}mX\033[0m"

Note, vt100 does NOT support color codes, it was a black and white only terminal, vt102 and vt220 and ansi are all terminal types that DO support ANSI color codes.

1 Like

Correct, it did only support bold, dim , reverse, blink, keyleds and cursorcontrols.
I'm not sure if it did underline, can't remember, too long ago since I used a vt100 :slight_smile:

For a complete list, see:

1 Like