Monday, August 10, 2009

Figlet - the better banner



Figlet is small tool a bit similar to described earlier (http://tuxshell.blogspot.com/2009/08/banner.html) banner command. It allows to create pretty nice ASCII art letters out of ordinary text. You can download it from http://www.figlet.org.

Installation

$ wget ftp://ftp.figlet.org/pub/figlet/program/unix/figlet222.tar.gz
$ tar zxvf figlet222.tar.gz
$ cd filglet222

We can set the default installation directory as well as the default fonts directory by editing the Makefile. I had to comment the following line:

# DEFAULTFONTDIR = fonts

to avoid installation error. Let's build and install:

$ make
$ su -c 'make install'

Usage

When no arguments are present, the program waits for input . Type what you want and see the result. It will render the text given as the first argument:

$ figlet hello world
 _          _ _                            _     _
| |__ ___| | | ___ __ _____ _ __| | __| |
| '_ \ / _ \ | |/ _ \ \ \ /\ / / _ \| '__| |/ _` |
| | | | __/ | | (_) | \ V V / (_) | | | | (_| |
|_| |_|\___|_|_|\___/ \_/\_/ \___/|_| |_|\__,_|

We can see all available fonts by listing *.flf files /usr/local/share/figlet/:

$ ls *.flf

banner.flf bubble.flf lean.flf script.flf small.flf smslant.flf
big.flf digital.flf mini.flf shadow.flf smscript.flf standard.flf
block.flf ivrit.flf mnemonic.flf slant.flf smshadow.flf term.flf


The -f switch selects the font:

$ figlet -f shadow shadow


| |
__| __ \ _` | _` | _ \\ \ \ /
\__ \ | | | ( | ( | ( |\ \ \ /
____/_| |_|\__,_|\__,_|\___/ \_/\_/

We can also set text justification with -c , -l, -r and -x switches:
$ figlet -l left

_ __ _
| | ___ / _| |_
| |/ _ \ |_| __|
| | __/ _| |_
|_|\___|_| \__|

$ figlet -c center
_
___ ___ _ __ | |_ ___ _ __
/ __/ _ \ '_ \| __/ _ \ '__|
| (_| __/ | | | || __/ |
\___\___|_| |_|\__\___|_|

$ figlet -r right
_ _ _
_ __(_) __ _| |__ | |_
| '__| |/ _` | '_ \| __|
| | | | (_| | | | | |_
|_| |_|\__, |_| |_|\__|
|___/

When sending to figlet the output from other file it's good to use -p switch. It switches the figlet into paragraph mode, which eliminates unnecessary line breaks when piping a multi-line file:

$ figlet -p < /etc/motd

The -k, -s and -S switches control the kerning of the letters. We can achieve the mirror effect by using the -R option which prints the text from right to left:

$ figlet -kR hello

_ _ _
___ | || | ___ | |__
/ _ \ | || | / _ \| '_ \
| (_) || || || __/| | | |
\___/ |_||_| \___||_| |_|

Combining figlet with tr command ale proper fonts leads us to some more interesting effects:

$ figlet -f lean hello | tr ' _/' '/  '
/////////////////////////////////////////
//// ////////////////// // ///////////
/// ////// //// // //// ////
// //// // // // // //// ///
/ //// // //////// // // //// ////
//// //// // // //// ///////
/////////////////////////////////////////
/////////////////////////////////////////

Of course we can pipe output of any command to the figlet. The imagination is the limit.

$ date | figlet
_____ _ _ _
|_ _| _ ___ / \ _ _ __ _ / / |
| || | | |/ _ \ / _ \| | | |/ _` | | | |
| || |_| | __/ / ___ \ |_| | (_| | | | |
|_| \__,_|\___| /_/ \_\__,_|\__, | |_|_|
|___/
___ ___ _________ _ ___ ____ _____ ____ _____
/ _ \ / _ \ _|___ / ___|_/ |/ _ \ / ___| ____/ ___|_ _|
| | | | (_) (_) |_ \___ (_) | | | | | | | _| \___ \ | |
| |_| |\__, |_ ___) |__) || | |_| | | |___| |___ ___) || |
\___/ /_/(_)____/____(_)_|\___/ \____|_____|____/ |_|

____ ___ ___ ___
|___ \ / _ \ / _ \ / _ \
__) | | | | | | | (_) |
/ __/| |_| | |_| |\__, |
|_____|\___/ \___/ /_/
We can run the full screen clock based on figlet:

$ watch -n1 "date +%H:%M:%S | figlet -k -c"

No comments:

Post a Comment