How to do: underline, bold, italic, strikethrough, and color in Gnome Terminal?
Bold
Italic
u̲n̲d̲e̲r̲l̲i̲n̲e̲
s̶t̶r̶i̶k̶e̶ ̶i̶t̶ ̶l̶i̶k̶̶e̶ ̶i̶t̶s̶ ̶h̶o̶t
background
font
< (its mono if you couldn't tell)
How to do: underline, bold, italic, strikethrough, and color in Gnome Terminal?
Bold
Italic
u̲n̲d̲e̲r̲l̲i̲n̲e̲
s̶t̶r̶i̶k̶e̶ ̶i̶t̶ ̶l̶i̶k̶̶e̶ ̶i̶t̶s̶ ̶h̶o̶t
background
font
< (its mono if you couldn't tell)
In Bash, the character can be obtained with the following syntaxes:
The commands (for easy copy-paste):
Source (including all types of foreground/background color codes): http://misc.flogisoft.com/bash/tip_colors_and_formatting
To extend Sylvain's answer, some helper functions:
Then
GNOME Terminal 3.28 (VTE 0.52), debuting in Ubuntu 18.04 LTS, adds support for a few more styles including curly and colored underlines as seen in Kitty, overline as seen in Konsole, and finally everyone's much loved or much hated blink attribute as well.
These also automatically work in any other VTE-based terminal emulator (e.g. Tilix, Terminator, Xfce4-terminal, Guake etc.), given that VTE is at least at version 0.52.
Here's a list demonstrating the standard escape sequences, as well as GNOME Terminal's (VTE's) additions. Note that for every opening sequence I'm also showing the closing sequence of that property only, rather than the generic
\e[m
or\e[0m
that disables all special modes.(*) Truecolor values for underlines are slightly approximated.
And a bit odd one that doesn't quite fit in this picture, as it's more of a functionality than a style, yet is probably worth mentioning here, is hyperlink support co-designed with iTerm2, available since GNOME Terminal 3.26 (VTE 0.50):
Here's a screenshot demonstrating the result:
Something that has not been covered yet is the combination of two or three parameters, e. g. bold and underline, in a predefined color. This is achieved by a 3-way syntax, for instance:
will cause "this is a test" to be printed in yellow color (
33m
), italic (3m
) AND underlined (4m
).Note that it is not necessary to repeat the
\e[
every time.Note too that (alike to Sylvain) I also added a
\e[0m
to reset settings every time, because otherwise the yellow color and the font style will remain active in terminal! Needless to say that you absolutely have to watch out for these to get reset in scripts, because users who use your scripts may dislike it if your script permanently modifies their color + style settings in terminal!Replace these hard-coded sequences by:
Refer to "man terminfo" and "man tput" for complete descriptions of these commands.
Example :