O'Reilly logo

Advanced Perl Programming by Sriram Srinivasan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Implementation

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:

$text->see($index)
  • Deleting entire contents:

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

$text->tagConfigure('search',  
                    'foreground' => yellow, 'background' => 'red');
  • Deleting a tag:

$text->tagDelete('search');
  • 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required