GUI Example: Man Page Viewer

Contents:
man and perlman
Implementation
Resources

Help wanted. Telepath. You know where to apply.

- Anonymous

The primary objective of this chapter is to exercise some of the most important capabilities of Tk's text widget; a man page viewer called perlman provides an ideal test case.[1] Now, you will familiarize yourself with the widget's text insertion, deletion, and retrieval capabilities; use a variety of indexing primitives; create and configure tags; and perform regular expression searching and highlighting of text. Along the way, you'll also learn to use entry widgets and construct menus dynamically.

[1] For a more ambitious workout of the text widget, you could try writing an HTML page viewer.

perlman is modeled after TkMan [5], a very nice man page viewer written by Thomas Phelps at the University of California at Berkeley, using Tcl/Tk. perlman contains only a small subset of TkMan's functionality.

Thomas has also written an experience paper entitled "Two Years with TkMan: Lessons and Innovations. Or, Everything I Needed to Know about Tcl/Tk I Learned from TkMan" [6]. It presents a good case for writing the entire utility in a scripting language and unwittingly convinces us, smug Perl developers that we are, why Perl would have been the ideal choice. Please see the "Resources" section at the end of this chapter for pointers to TkMan and this paper.

man and perlman

Unix manual pages are normally viewed by the man(1) command. When you say man perl at the command line, it searches the list of directories indicated by the environment variable MANPATH, a colon-separated list of pathnames. (If MANPATH is not specified, man(1) looks at standard locations, such as /usr/man.) Once it finds a file called perl.1, it calls tbl to format the tables and nroff to format the text, and pipes the output through a suitable pager, such as more(1) or less(1).

Figure 16.1: perlman screen

Figure 16.1

perlman, shown in Figure 16.1, is a GUI wrapper over man. To view a topic, you have to enter a string in the "Show" box and press the Return key. To highlight all pieces of text matching a given regular expression, simply enter it in the "Search" box and press Return. You can also perform exact string searches and ignore case optionally. In addition, perlman provides the following features: