Using SGR5 in Windows Terminal

With the release of Windows Terminal 1.4 support for SGR 5 parameters were added. SGR (Select Graphic Rendition) parameters sets display attributes when you’re showing text on a terminal. These attributes can alter things like colour of the text and now also, and with this Windows Terminal release, you can make the text blink.

The easiest way to to get started is pick a ready made ASCII art and then add some blinking colour to it. For this illustration I picked a lighthouse.

To get right to it, create a new bash file lighthouse.sh and add the following code to the file.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
echo -e ""
echo -e "            +             \033[5;1;33m/\033[0m"
echo -e "\033[5;1;33m\\ \033[0m          |           \033[5;1;33m/\033[0m"
echo -e "  \033[5;1;33m\\ \033[0m        |         \033[5;1;33m/\033[0m"
echo -e "    \033[5;1;33m\\ \033[0m     / \\      \033[5;1;33m/\033[0m"
echo -e "      \033[5;1;33m\\ \033[0m /_____\  \033[5;1;33m/\033[0m"
echo -e "      \033[5;1;33m/\033[0m  |\033[5;1;33m\u2588\u2588\033[0m|\033[5;1;33m\u2588\u2588\033[0m|  \033[5;1;33m\\ \033[0m"
echo -e "    \033[5;1;33m/\033[0m  |;|     |;|  \033[5;1;33m\\ \033[0m"
echo -e "  \033[5;1;33m/    \033[0m\\.    .   /    \033[5;1;33m\\ \033[0m"
echo -e "\033[5;1;33m/\033[0m       ||:  .  |       \033[5;1;33m\\ \033[0m"
echo -e "        ||:     |         \033[5;1;33m\\ \033[0m"
echo -e "        ||:.    |           \033[5;1;33m\\ \033[0m"
echo -e "        ||:    .|"
echo -e "        ||:   , |         /-\\"
echo -e "        ||:     |                                          /-\\"
echo -e "        ||: _ . |                             /-\\"
echo -e "       _||_| |__|                      \033[04m____"
echo -e "  ____~\033[0m    |_|  |___           \033[94m__-----~    ~---,__             ___"
echo -e "-~                  ~---___,--~                  ~~----_____-~"
echo -e "~----,____                      \033[0m -Niall-"
echo -e ""
echo -e ""

To run this script showing a lighthouse, you first have to make the file executable. On Linux, that’s done like this.

1
chmod 755 lighthouse.sh

After that, you can add ~/lighthouse.sh at the end of your login script .bashrc, and, voila, you have a pimped login screen for your WSL terminal.

Lighthouse in windows terminal

So how does it work? The key is the escape character \033. It’s not specific to bash but is rather interpreted by Windows Terminal.

The SGR codes used in the example are

Code Effect
0 Reset to normal
1 Bold
5 Slow blink
33 Yellow
94 Bright blue

You can specify several SGR codes at once after the escape character by starting with [ and ending with m. Some examples:

Change terminal output to slow blinking, bold and yellow

1
\033[5;1;33m

Change terminal output to bright blue

1
\033[94m

Reset terminal output to normal

1
\033[0m

By alternating these three examples, we’re able to create a blinking effect in the ASCII art making the light pulsate and the water turn blue.

There are a lot more things you can do as shown here. If you want to build more advanced things you can also use blocks. I had to change the windows of the lighthouse to use unicode block elements instead to make the colour fill up the whole window.

You might think that blinking text isn’t that useful - and you’re right. But it’s fun, you have to admit that.

Load Comments?