Mr Speaker

mrspeaker's head in a monitor You find yourself at the entrance to the Hompage of Mr Speaker. In a darkened corner sits a trunk containing HTML5 games and some JavaScript tidbits. Next to it you spy a mastodon account. Exits are North, East, and .

Fire/Escape

Well well well, it's been quite a while! Nice to see you again. Sorry for the delay... I forgot my blog password, and I had to run some errands, the decade just got away from me. Anyway, the password was qwerty123 so let's get on with it...

Today's thing is a terminal-based 90s demo effect using ANSI escape sequences (here 'tis on youtube). It's the first such sequences I've written by hand. I kind of knew they existed, but just thought they were encoding errors to be cut and paste from random blogs to make the command line prompt all colorful. Turns out they are not at all complicated: just a couple of bytes that signal to your terminal emulator you want to do something besides printing boring text.

Fire/Escape

All of the sequences start with the code generated when you hit the "escape" key. But you can't press escape inside a string in your text editor though - so you need to use the escape character "\e" (AKA "\x1b", AKA "\033", AKA "\27" in hex, octal, and decimal respectively) followed by a "[". This is called a Control Sequence Introducer (CSI). It introduces the control sequence. When your terminal sees this it will know you want to do something fancy, not just print to the screen.

The most common fancy thing to do is change the text color. This is done with the command 38;5;<n>m, where <n> is the color you want to change to. So, try this out in your terminal emulator: echo -e "\e[38;5;2mWhy, hello". You should get the text "Why, hello" in green (by the way, the -e flag in echo is to say "interpret escape sequences - don't just print \e thanks"). Here's a list of the standard-ish colors: