Search code examples
colorscmdluaasciiansi-escape

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.


Solution

  • 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