% LibTermFns_

LibTermFns Overview:

LibTermFns is a library that provides a wrapper around terminal-based properties for C++ programs. Included routines include functions for colored text, clearing the screen, moving cursor positions, querying and setting keyboard LEDs, and key remapping. In addition to the wrapper functions the library contains (POSIX) thread-based functions for console widgets such as interactive progress bars, animated text, hierarchical menus, and more. The source distribution contains a number of example programs that demonstrate usage of the library and reveal the beginnings of what can be coded with it. The target system for LibTermFns is a modern version of Linux. However, any modern Unix system (within reason) can operate with the core of text manipulation functions.

Current Version: LibTermFns-1.0.tar.gz   [Download] [README]
Contact Information:   maxieds@gmail.com


The documentation for LibTermFns and the example programs in the source is the README (also found in the library source). If something is missing, or there is an error (or typo), send me an e-mail at maxieds(AT)gmail.com.

The platform with the most coverage of features is Linux (the author lives on Gentoo). The following Linux-specific man pages are useful to consult when attempting to pick apart the code:

  • "man console_ioctl"
  • "man console_codes"
  • "man tty_ioctl"
  • "man ioctl_list"

Additionally, this site contains a number of console-related information, in particular the keys table used to generate the key defs in LibTermFns. See the next section for more console-related code and references.

Related Programs and Information:

Much of the LibTermFns code was based on picking through the source to various commandline utilities (see below for a list of man pages for several of these programs). The following list is a nice collection of code worth checking out:

  • CoreUtils (stty, tty)
  • Console-Tools (kbdtools directory)
  • TermUtils (tput, tabs)
  • UtilLinux (setterm)
  • SVGATextMode
  • TtySnoop : The program monitors a tty device and has enough extra features that the source code is worth a look. There is also an example in the LibTermFns (TTY_sniff) that implements this differently. The base of these programs is that a tty is a character device that can be written to or read from in plain-text (try "echo plain-text > /dev/tty") corresponding to STDIN and STDOUT on a non-virtual terminal (see proc(5)) on a Linux box.
  • Getting Decent Colors On The Linux Console : the link gives several decent examples of how to change the 16-color RGB (0 to 255) palette used with Linux consoles. There are several ways to do this: 1) Linux-specific ioctl calls (see "man console_ioctl"); 2) Escape sequences (see "man console_codes"); 3) xterm-specific codes (see the official documentation); in addition to this check out "test_code/TFNS-linux/console_codes_palette.info.txt" in the source distribution and spare some frustrations trying to figure out how the colors get used and defined;

The following two (Linux-specific) headers are used in the library. The first has defs corresponding to a number of the Linux ioctl calls (see "man console_ioctl" on a Linux box). The second is (mostly) the remainder of the ioctl defs given in man console_ioctl, again on a Linux box:

  • #include <linux/kd.h> (path: "/usr/include/linux/kd.h")
  • #include <linux/vt.h> (path: "/usr/include/linux/vt.h")
Program Man Page Listing:
stty(1), setterm(1), proc(5), w(1), pts(4), dumpkeys(1), kbd_mode(1), loadkeys(1), setleds(1), tty(4), mapscrn(8), tput(1), showkey(1), keymaps(5);