terminfofont.lua - a big font for use in a console or an xterm


 local TIF = require 'terminfofont'

 TIF.rectfill(TIF.cols*0.2, 18, TIF.cols*0.6, 15, 'cyan')
 local line = 6
 local dx, dy
 dx,dy = TIF.show(1, line, 'ABCDEFG', 1)
 line = line + dy
 dx,dy = TIF.show(1, line, 'HIJKLMN', 4)
 line = line + dy
 local x = (TIF.cols - TIF.stringwidth('Goog')) / 2  -- place centrally
 dx,dy = TIF.show(x, line, 'GooG', 'violet')

 TIF.moveto(0, TIF.lines-1)


This module implements in Lua a big font, seven lines high, for use when terminfo is supported, such as in a console, or an xterm.   It was inspired by the Bitfont5x7 font in the PostScript module fonts.ps, and the functions were inspired by PostScript procedures.   These are some screenshots on a 79x23 xterm . . .


show(), stringwidth(), moveto(), rectfill(),   clear(), civis(), cnorm()

width, height = TIF.show (x,y, string, colour)

This displays the string, starting at column x and line y, in the ANSI colour colour.
It returns the width and height (in columns and lines) of the string.
As in PostScript, the position x and y specifies the bottom-left corner of the letters.

The available colours are:   black=0, red=1, green=2, yellow=3, blue=4, violet=5, cyan=6, and white=7
See man terminfo in the Colour Handling section, where it discusses the setaf and setbf capabilites, and show also supports the colours begin given as strings, for example 'red'

width, height = TIF.stringwidth (string)

This returns the width and height (in columns and lines) that the string would have if it were displayed.   It's like the show function, except that nothing is displayed.

TIF.moveto (x, y)

This moves the cursor to a given position, specified as column and line.
x and y are 0, 0 in the top left corner, and increasing y moves downwards.

TIF.rectfill (x,y, width,height, colour)

This creates and fills a rectangle with corner at x, y and the given width and height, in the ANSI colour colour.
Be aware that most terminal-fonts are about twice as high as they are wide, eg 10x20 or 12x24, so that to get something like a square you have to specify something like   TIF.rectfill(10,35, 50,25, 'blue')
As in PostScript, the position x and y specifies the bottom-left corner of the rectangle (assuming width and height are positive).

TIF.clear ()

This clears the screen, just like   os.execute('clear')

TIF.civis ()

This makes the cursor invisible

TIF.cnorm ()

This makes the cursor normal again


To save you from having to require 'terminfo', some integer constants:   TIF.lines and TIF.cols


This module exists as a LuaRock in luarocks.org/modules/peterbillam so you can install it with the command:
  sudo luarocks install terminfofont

  sudo luarocks install http://www.pjb.com.au/comp/lua/terminfofont-0.3-0.rockspec

You will also need the terminfo module:
  sudo luarocks install terminfo

The test script used during development is pjb.com.au/comp/lua/test_terminfofont.lua


 20191109 0.3 introduce clear() and $
 20191108 0.2 rename go_to as moveto, introduce rectfill
 20191106 0.1 first released version


Peter J Billam,   pjb.com.au/comp/contact.html


man terminfo