Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I apply formatting like italic or bold to text using ANSI escaping sequences in a console?

How do I format text with ANSI escaping?

Like make things italic or bold and maybe strikethrough and super script.

like image 441
jepjep40 Avatar asked Jul 26 '16 16:07

jepjep40


People also ask

How do you format text italics and bold?

To make text bold, select and highlight the text first. Then hold down Ctrl (the control key) on the keyboard and press B on the keyboard. To make text italic, select and highlight the text first. Then hold down Ctrl (the control key) on the keyboard and then press the I on the keyboard.

How do ANSI escape codes work?

ANSI escape sequences are a standard for in-band signaling to control cursor location, color, font styling, and other options on video text terminals and terminal emulators. Certain sequences of bytes, most starting with an ASCII escape character and a bracket character, are embedded into text.

Which command is used to apply italic formatting?

The shortcut key to make text italic is Ctrl + I on the PC and Chromebook or Command + I on the Mac. To make text italic using a keyboard shortcut, highlight the text and then press the shortcut key.


1 Answers

How I format like, make things italic or bold using ANSI terminal escape codes?

Bold: Use ESC[1m

Italic, Strike-through and Superscript are not supported.

Some terminals support additional sequences. For example in a Gnome Terminal you can use:

echo -e "\e[1mbold\e[0m"
echo -e "\e[3mitalic\e[0m"
echo -e "\e[4munderline\e[0m"
echo -e "\e[9mstrikethrough\e[0m"
echo -e "\e[31mHello World\e[0m"
echo -e "\x1B[31mHello World\e[0m"

enter image description here

Source How to do: underline, bold, italic, strikethrough, color, background, and size in Gnome Terminal?, answer by Sylvain Pineau


Further Reading

  • ANSI Escape sequences
like image 73
DavidPostill Avatar answered Oct 07 '22 00:10

DavidPostill