As of 2016-02-26, there will be no more posts for this blog. s/blog/pba/
Showing posts with label pyfiglet. Show all posts

termdown is a big text timer using pyfiglet for FIGlet-like text, it can count down or be used as stopwatch.

https://lh3.googleusercontent.com/-cMjMSqx2nVg/Vo7b9iVz-rI/AAAAAAAAI1E/FLAGcUNZwoI/s800-Ic42/termdown.gif

./termdown.py 5 --title termdown --text "Time's Up!" --font computer

You can specify the time by seconds or something like 13:45 or 1h 23m 45s. Also a few keys, such as Space to pause the timer.

A set of various options, you can let screen blink when times up, render seconds in red, choose different pyfiglet font, hide seconds until last minute, show a title text and/or end text, speak the second if on Mac OS X, or not to use ASCII art text.

termdown was created by Torsten Rehn, et al. on 2014-05-26, written in Python 2/3 with pyfiglet under GPLv3, currently git-6602526 (2016-01-07, post v1.9.0 (2015-10-24))

Everyone knows FIGlet or at least have seen once or twice the output of FIGlet even whether they know what generates those or not. But not everyone knows that there is a port1 of FIGlet, I was one of them until I came across a program called termdown, which is a countdown timer and depends on the port of FIGlet, pyfiglet:

                        _|_|  _|            _|              _|
_|_|_|    _|    _|    _|            _|_|_|  _|    _|_|    _|_|_|_|
_|    _|  _|    _|  _|_|_|_|  _|  _|    _|  _|  _|_|_|_|    _|
_|    _|  _|    _|    _|      _|  _|    _|  _|  _|          _|
_|_|_|      _|_|_|    _|      _|    _|_|_|  _|    _|_|_|      _|_|
_|              _|                      _|
_|          _|_|                    _|_|

Lets compare the CLIs, FIGlet v2.2.2 (2005-08-05) and pyfiglet v0.7 (2014-06-08):

$ figlet -h
figlet: invalid option -- 'h'
Usage: figlet [ -cklnoprstvxDELNRSWX ] [ -d fontdirectory ]
              [ -f fontfile ] [ -m smushmode ] [ -w outputwidth ]
              [ -C controlfile ] [ -I infocode ] [ message ]

$ pyfiglet -h
Usage: pyfiglet [options] [text..]

Options:
  --version             show program's version number and exit
  -h, --help            show this help message and exit
  -f FONT, --font=FONT  font to render with (default: standard)
  -D DIRECTION, --direction=DIRECTION
                        set direction text will be formatted in (default:
                        auto)
  -j SIDE, --justify=SIDE
                        set justification, defaults to print direction
  -w COLS, --width=COLS
                        set terminal width for wrapping/justification
                        (default: 80)
  -r, --reverse         shows mirror image of output text
  -F, --flip            flips rendered output text over
  -l, --list_fonts      show installed fonts list
  -i, --info_font       show font's information, use with -f FONT

Well, I cant say its fully ported in terms of options, but I would say they are close, the CLI isnt the point here, but the programmical interface is, that you can just get a FIGlet-style output right in your Python script. I always shake my head whenever I see someone coding something like the following:

os.system('clear')
os.system('tput cup 0 0')

Why do I dislike code above? Just think about should you do in that way, you would understand why usually think this isnt a good idea.

With pyfiglet, you dont need to pipe in FIGlet if you really want those big text with fancy fonts. You just import the library and generate like, from README:

>>> from pyfiglet import Figlet
>>> f = Figlet(font='slant')
>>> print f.renderText('text to render')
   __            __     __                               __
  / /____  _  __/ /_   / /_____     ________  ____  ____/ /__  _____
 / __/ _ \| |/_/ __/  / __/ __ \   / ___/ _ \/ __ \/ __  / _ \/ ___/
/ /_/  __/>  </ /_   / /_/ /_/ /  / /  /  __/ / / / /_/ /  __/ /
\__/\___/_/|_|\__/   \__/\____/  /_/   \___/_/ /_/\__,_/\___/_/

It supports many fonts, maybe even all of FIGlet fonts, run pyfiglet -l to get the list.

pyfiglet is made by Christopher Jones, Stefano Rivera, and Peter Waller, under the GPLv2. It first appeared in 2007, now the version 0.7 (2014-06-08), works for both Python 2 and 3.

[1]There is a project called TOIlet, although it can loads FIGlets fonts, I dont know if its considered as a port or not.