Quantcast
Viewing all articles
Browse latest Browse all 10

Linux / Unix Desktop Fun: Text Mode ASCII-art Box and Comment Drawing

Boxes command is a text filter and a little known tool that can draw any kind of ASCII art box around its input text or code for fun and profit. You can quickly create email signatures, or create regional comments in any programming language. This command was intended to be used with the vim text editor, but can be used with any text editor which supports filters, as well as from the command line as a standalone tool.

Task: Install boxes

Use the apt-get command or apt command to install boxes under a Debian / Ubuntu Linux:
$ sudo apt-get install boxes
Sample outputs:

[sudo] password for vivek: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  boxes
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 66.6 kB of archives.
After this operation, 194 kB of additional disk space will be used.
Get:1 http://in.archive.ubuntu.com/ubuntu artful/universe amd64 boxes amd64 1.2-2 [66.6 kB]
Fetched 66.6 kB in 2s (27.5 kB/s)
Selecting previously unselected package boxes.
(Reading database ... 201669 files and directories currently installed.)
Preparing to unpack .../archives/boxes_1.2-2_amd64.deb ...
Unpacking boxes (1.2-2) ...
Setting up boxes (1.2-2) ...
Processing triggers for man-db (2.7.6.1-2) ...

CentOS / Fedora Linux users, use the yum command to install boxes (first enable EPEL repo as described here on a CentOS/RHEL 6.x, if you are using a CentOS/RHEL 7.x see this page to enable EPEL repo):
# yum install boxes
Sample outputs:

Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.iitm.ac.in
 * epel: repo.ugm.ac.id
 * extras: ftp.iitm.ac.in
 * updates: ftp.iitm.ac.in
Resolving Dependencies
--> Running transaction check
---> Package boxes.x86_64 0:1.1.1-4.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===============================================================================
 Package         Arch             Version                 Repository      Size
===============================================================================
Installing:
 boxes           x86_64           1.1.1-4.el7             epel            66 k

Transaction Summary
===============================================================================
Install  1 Package

Total download size: 66 k
Installed size: 157 k
Is this ok [y/d/N]: y
Downloading packages:
boxes-1.1.1-4.el7.x86_64.rpm                              |  66 kB   00:02     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : boxes-1.1.1-4.el7.x86_64                                    1/1 
  Verifying  : boxes-1.1.1-4.el7.x86_64                                    1/1 

Installed:
  boxes.x86_64 0:1.1.1-4.el7                                                   

Complete!

Fedora Linux user try dnf command:
$ sudo dnf install boxes
FreeBSD user can use the port as follows:
cd /usr/ports/misc/boxes/ && make install clean
Or, add the package using the pkg_add command:
# pkg install boxes

Draw any kind of box around some given text

Type the following command:

echo "This is a test" | boxes

Or specify the name of the design to use:

echo -e "\n\tVivek Gite\n\tvivek@nixcraft.com\n\twww.cyberciti.biz" | boxes -d dog

Sample outputs:

Image may be NSFW.
Clik here to view.
Unix / Linux: Boxes Command To Draw Various Designs
Fig.01: Unix / Linux: Boxes Command To Draw Various Designs

How do I list all designs?

The syntax is:

boxes option
pipe | boxes options
echo "text" | boxes -d foo
boxes -l

The -d design option sets the name of the design to use. The syntax is:

echo "Text" | boxes -d design
pipe | boxes -d design

The -l option list designs. It produces a listing of all available box designs in the config file, along with a sample box and information about it’s creator:

boxes -l
boxes -l | more
boxes -l | less

Sample outputs:

43 Available Styles in "/etc/boxes/boxes-config":
-------------------------------------------------

ada-box (Neil Bird ):

    ---------------
    --           --
    --           --
    ---------------

ada-cmt (Neil Bird ):

    --
    -- regular Ada
    -- comments
    --

boy (Joan G. Stark ):

                    .-"""-.
                   / .===. \
                   \/ 6 6 \/
                   ( \___/ )
      _________ooo__\_____/______________
     /                                   \
    |   joan stark   spunk1111@juno.com   |
    |     VISIT MY ASCII ART GALLERY:     |
    | http://www.geocities.com/SoHo/7373/ |
     \_______________________ooo_________/  jgs
                    |  |  |
                    |_ | _|
                    |  |  |
                    |__|__|
                    /-'Y'-\
                   (__/ \__)

....
...
output truncated
..

How do I filter text via boxes while using vi/vim text editor?

You can use any external command with vi or vim. In this example, insert current date and time, enter:
!!date
OR
:r !date
You need to type above command in Vim to read the output from the date command. This will insert the date and time after the current line:

Tue Jun 12 00:05:38 IST 2012

You can do the same with boxes command. Create a sample shell script or a c program as follows:

#!/bin/bash
Purpose: Backup mysql database to remote server.
Author: Vivek Gite
Last updated on: Tue Jun, 12 2012

Now type the following (move cursor to the second line i.e. line which starts with “Purpose: …”)

3!!boxes

And voila you will get the output as follows:

#!/bin/bash
/****************************************************/
/* Purpose: Backup mysql database to remote server. */
/* Author: Vivek Gite           */
/* Last updated on: Tue Jun, 12 2012                */
/****************************************************/

This video will give you an introduction to boxes command:

Getting more info about the command:
$ boxes --help
Sample outputs:

boxes - draws any kind of box around your text (and removes it)
        (c) Thomas Jensen 
        Web page: http://boxes.thomasjensen.com/
Usage:  boxes [options] [infile [outfile]]
        -a fmt   alignment/positioning of text inside box [default: hlvt]
        -c str   use single shape box design where str is the W shape
        -d name  box design [default: first one in file]
        -f file  configuration file
        -h       print usage information
        -i mode  indentation mode [default: box]
        -k bool  leading/trailing blank line retention on removal
        -l       list available box designs w/ samples
        -m       mend box, i.e. remove it and redraw it afterwards
        -p fmt   padding [default: none]
        -r       remove box
        -s wxh   box size (width w and/or height h)
        -t str   tab stop distance and expansion [default: 8e]
        -v       print version information

See also

  • boxes man page

The post Linux / Unix Desktop Fun: Text Mode ASCII-art Box and Comment Drawing appeared first on nixCraft.


Viewing all articles
Browse latest Browse all 10

Trending Articles