Colored Text with toilet

📅 November 13, 2015
toilet01If you enjoy using figlet to produce fancy text within a terminal, then why not give toilet a try?

Not only is toilet compatible with figlet’s fonts, but basic filters can be applied that color the text, add a border, and flip and flop without the need for Imagemagick.

Installation

Toilet is available from the repository (Ubuntu-based). To install toilet,

sudo apt-get update
sudo apt-get install toilet

And install figlet if you do not have it already.

sudo apt-get install figlet

About toilet

Think of toilet as “figlet with filters.” Toilet does much the same as figlet, but with more features. If specifying a font using the -f option, toilet can produce the same output as figlet.

a

Both toilet and figlet produce the same style of output from standard input.

Fonts are located in the same /usr/share/figlet directory as .flf files, so make sure that figlet is installed in order to use them.

In the example, both use the same font, smblock. Without specifying a font, toilet produces something like this:

a

Not exactly readable. toilet wraps at 80 columns by default, but this can be changed using the -w option.

Consult man toilet to view the full list of options.

Filters

Filters are what set toilet apart from figlet. Using a filter, we can give the text a metal-like appearance using blue and gray colors.

a

Normal and filtered. the –filter metal option colors the output.

To view a list of filters, enter toilet –filter list at the command prompt in a terminal. There are not many filters to choose from, but they are enough play with.

To use a filter, enter the –filter option followed by the filter’s name.

toilet --filter metal 'Linux is fun!'
a

Colored text using a filter!

Filters can be combined using a colon-delimited list of filter names.

a

Here are three different output variations by combining filters.

--filter border:metal

Adds a colored border around colored text.

--filter border:metal:flip

Flips the texts horizontally, colors it, and adds a border.

--filter border:metal:flip:flop

Displays colored text upside down and backwards within a border.

Adjusting the Width

Sometimes the default 80-column wrap is too much. We can adjust the width using the -w option followed by the number of columns at which to wrap.

a

Default wrap at 80 columns. This text fits just right, but longer text might appear ugly.

 

a

Here, the text wraps at 40 columns by using -w 40.

HTML Output

With the –html option, toilet will output the result to an HTML file so you can use the styled text in a web browser.

toilet -f smblock --filter border:metal 'Welcome to the colored toilet!' --html > test.htm
a

This text was produced the same as shown above, but the output was redirected to test.htm. When test.htm was opened in a web browser, the text appeared the same as in a terminal. It does not generate an image, but instead, toilet styles individual characters (using spans and inline styles) so the markup can be copied and pasted into a page.

toilet --export list

the –export list option will list all possible output formats the generated text can be exported to.

a

List of built-in export formats.

Output Image

toilet will output to an .svg or .tga file, so images are possible. Use the –export svg or –export tga and redirect the output to a file.

toilet -f smblock --filter border:metal 'Welcome to the colored toilet!' --export svg > test.svg
a

toilet generated an SVG file, which was converted into this PNG image using GIMP.

More ASCII Fun

Try combing toilet with other programs, such as fortune and cowsay.

fortune | cowsay | toilet --metal -f term
a

Displays the cowsay ASCII art and fortune text using the metal filter from toilet. Be sure to use the -f term option with toilet to preserve the ASCII text.

fortune | cowsay -f eyes | toilet --metal -f term
a

Changed the cowsay image using -f eyes.

 linuxlogo -a -l | toilet --metal -f term
a

Coloring the linuxlogo output with the metal filter. Be sure to use the -a option with linuxlogo.

linuxlogo -logo -a | toilet -f term --filter flip | lolcat
a

Backwards with gradient color. Here, the program lolcat produces the color. toilet is used to flip the output.

toilet -f ivrit 'Linux is fun!' | boxes -d cat -a hc -p h8 | lolcat
a

Combined with boxes and lolcat. toilet only sets the font and text.

Conclusion

Is toilet useful? Why, YES! If you enjoy twiddling with ASCII art, ASCII banners, and find ASCII creations to be wonderful playthings, then toilet belongs in the ASCII toolbox alongside figlet, cowsay, linuxlogo, and all of the other fun ASCII generation programs.

Have fun!

,

  1. Leave a comment

Leave a comment