Today I Learned

hashrocket A Hashrocket project

ANSI Escape Codes

Today I learned that ANSI Escape Codes are a thing.

I was writing some Rails migrations and wanted nice readable output and a quick way to tell how things were going. So, I wanted some colored text to be displayed as output. This was how I learned about ANSI Escape Codes.

In short, you want to escape your string using \e then give it the prefix [ and then give it a series of codes to format your text.

For example, you can color all further text green using the code 32m or red using 31m.
If you want text to go back to normal give it the code 0m.

Here is an example: image

You can do other formatting than just color, but I found these to be helpful for what I needed and I didn't realize how simple it was.

See More #workflow TILs