ASCII art fun with boxes

314

Author: Shashank Sharma

ASCII art has evolved from flashy text messages cooked up with underscores and hashes to more complex and appealing designs, but creating such patterns takes some effort. boxes is an excellent utility that can help you create interesting ASCII artwork.

On a Debian system, boxes is just an apt-get install away. You can also get the source tar.gz package from the downloads page, along with simple installation instructions.

Using boxes from the command line is a breeze. The syntax is boxes -d <designtype>; the -d switch is for telling boxes the design name. There are a lot of designs available, such as dog, columns, and peek. The examples page has a description of many designs.

As an example, to create ASCII art in columns, type boxes -d columns and press Enter, then write your message. If you need to use multiple lines, just keep hitting Enter wherever required. Once you are done, press Ctrl-d and your ASCII art will be displayed on the screen.

boxes also allows you to describe the size attributes of a design, such as width and padding, using the -s switch. The -a switch can be used to specify the positioning of the text.

A complete list of all supported designs is available at the designs page. All the designs are defined in a config file that resides in /usr/share/boxes/boxes, at least on my Ubuntu system.

In addition to using boxes from the command line, you can also tie it to text editors such as Vim and Emacs to generate things like comments in C code. To integrate boxes with Vim, you need to edit your ~/.vimrc file. As per the installation page, you only need two lines to integrate boxes with Vim:

vmap ,mc !boxes -d c-cmt<CR>
nmap ,mc !!boxes -d c-cmt<CR>

The <CR> should be included in your file. Now, in the visual mode in Vim, when you enter ,mc, the command boxes -d c-cmt gets executed. Alternatively, you can just call a filter from the visual mode by typing ! or !! if you are in the normal mode. When you call a filter, .! appears at the bottom left of the Vim window, and allows you to run the boxes command.

boxes can work on a selection of text or just one line. By default, it operates only on the current line. To select multiple lines, press “v” in the normal mode and then use the arrow keys to make the selection. .!boxes -d dog would create ASCII art where your message, as selected using “v,” is displayed on a plaque held up by a dog.

If the ease of creating beautiful artwork inspires you to create your own designs, read through the documentation and get busy!

Shashank Sharma is studying for a degree in computer science. He specializes in writing about free and open source software for new users.