perlman’s implementation can be logically divided into four chunks:

  • Formatting and displaying man pages in the text widget: the routines show_man and get_command_line.

  • Search facility: search.

  • Screen layout: create_ui.

  • Displaying the list of help topics available in every section. We will not look at this particular piece of functionality, because it does not have much user interface code.

Before we barrel into each of the subroutines mentioned above, let us briefly study all the capabilities of the text widget used by perlman:

  • Inserting text at end, and marking it with a tag (“section”):

$text->insert('end', 'sample text', 'section');
  • Retrieving a stretch of text between two indices:

$line = $text->get($start_index, $end_index);
  • Ensuring that a particular index is visible:

  • Deleting entire contents:

$text->delete('1.0', 'end'); # From line 1, column 0, to end
  • Creating and configuring a tag:

                    'foreground' => yellow, 'background' => 'red');
  • Deleting a tag:

  • Applying a tag to a range of text, given an index position and number of characters:

$text->tagAdd('search', $current, "$current + $length char");
  • Listing all mark names and deleting each of them:

foreach $mark ( $text->markNames() ) { $text->markUnset($mark); }
  • Getting the line and column number (the index) from logical positions:

# row and col of current end position
$index = $text->index('end');
# go to current insert position, then to the beginning of the word ...

Get Advanced Perl Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.