IO::Pager::Perl(3) User Contributed Perl Documentation IO::Pager::Perl(3)

IO::Pager::Perl - Page text a screenful at a time, like more or less

    use Term:ReadKey; #Optional, but recommended
    use IO::Pager::Perl;
    my $t = IO::Pager::Perl->new( rows => 25, cols => 80 );
    $t->add_text( $text );
    $t->more();

This is a module for paging through text one screenful at a time. It supports the features you expectcusing the shortcuts you expect.

IO::Pager::Perl is an enhanced fork of Term::Pager.

    $t = IO::Pager::Perl->new( option => value, ... );

If no options are specified, sensible default values will be used. The following options are recognized, and shown with the default value:

The number of rows on your terminal. The terminal is queried directly with Term::ReadKey if loaded or "stty" or "tput", and if these fail it defaults to 25.
The number of columns on your terminal. The terminal is queried directly with Term::ReadKey if loaded or "stty" or "tput", and if these fail it defaults to 80.
The speed (baud rate) of your terminal. The terminal is queried directly with Term::ReadKey if loaded or "stty", and if these fail it defaults to a sensible value.
Exit at end of file.
Wrap long lines.
If true, line numbering is added to the output.
If defined, the pager will pause when the this character sequence is encountered in the input text. Set to ^L i.e; "\cL" to mimic traditional behavior of "1" in more.
Pass control characters from input unadulterated to the terminal. By default, chracters other than tab and newline will be converted to caret notation e.g; ^@ for null or ^L for form feed.
Collapse multiple blank lines into one.
Add a column with markers indicating which row match a search expression.
Flash the screen when beeping.

Accessors

There are accessors for all of the above properties, however those for rows, cols, speed, fold and squeeze are read only.

  #Is visualBeep set?
  $t->visualBeep();
  #Enable line numbering
  $t->lineNo(1);

You will need some text to page through. You can specify text as as a parameter to the constructor:

    text => $text

Or even add text later:

    $t->add_text( $text );

If you wish to continuously add text to the pager, you must setup your own event loop, and indicate to "more" that it should relinquish control e.g;

    eval{
        while( $t->more(RT=>.05) ){
          ...
          $t->add_text("More text to page");
        }
    };

The eval block captures the exception thrown upon termination of the pager so that your own program may continue. The RT parameter indicates that you wish to provide content in real time. This value is also passed to "ReadKey" in Term::ReadKey as the maximum blocking time per keypress and should be between 0 and 1, with larger values trading greater interface responsiveness for slight delays in output. A value of -1 may also be used to request non-blocking polls, but likely will not behave as you would hope.

NOTE: If Term::ReadKey is not loaded but RT is true, screen updates will only occur on keypress.

It is possible to extend the features of IO::Pager::Perl by supplying the "add_func" method with a hash of character keys and callback values to be invoked upon matching keypress; where \c? represents Control-? and \e? represents Alt-? The existing pairings are:

        'h' => \&help,
        'q' => \&done,
        'r' => \&refresh,       #also "\cL"
        "\n"=> \&downline,      #also "\e[B"
        ' ' => \&downpage,      #also "\cv"
        'd' => \&downhalf,
        'b' => \&uppage,        #also "\ev"
        'y' => \&upline,        #also "\e[A"
        'u' => \&uphalf,
        'g' => \&to_top,        #also '<'
        'G' => \&to_bott,       #also '>'
        '/' => \&search,
        '?' => \&hcraes,        #reverse search
        'n' => \&next_match,    #also 'P'
        'p' => \&prev_match,    #also 'N'
        "\e[D" => \&move_left,
        "\e[C" => \&move_right,
        '#' => \&toggle_numbering,

And a special sequence of a number followed by enter analogous to:

        '/(\d+)/'   => \&jump(\1)

if the value for that key is true.

The "dialog" method may be particularly useful when enhancing the pager. It accepts a string to display, and an optional timeout to sleep for before the dialog is cleared. If the timeout is missing or 0, the dialog remains until a key is pressed.

    my $t = IO::Pager::Perl->new();
    $t->add_text("Text to display");
    $t->add_func('!'=>\&boo);
    $t->more();
    sub boo{ my $self = shift; $self->dialog("BOO!", 1); }

Should you add additional functionality to your pager, you will likely want to change the contents of the help dialog or possibly the status line. Use the "I18N" method to replace the default text or save text for your own interface.

    #Get the default help text
    my $help = $t->I18N('help');
    #Minimal status line
    $t->I18N('prompt', "<h> help");

Current text elements available for customization are:

    404      - search text not found dialog
    bottom   - prompt line end of file indicator
    continue - text to display at the bottom of the help dialog
    help     - help dialog text, a list of keys and their functions
    prompt   - displayed at the bottom of the screen
    status   - brief message to include in the status line
    top      - prompt line start of file indicator

status is intended for sharing short messages not worthy of a dialog e.g; when debugging. You will need to call the "prompt" method after setting it to refresh the status line of the display, then void status and call "prompt" again to clear the message.

Scalability

The help text will be split in two horizontally on a null character if the text is wider than the display, and shown in two sequential dialogs.

Similarly, the status text will be cropped at a null character for narrow displays.

This modules currently only works in UN*X-like environment.

For simplicity, the current implementation loads the entire message to view at once; thus not requiring a distinction between piped contents and files. This may require significant memory for large files.

This module uses Termcap, which has been deprecated the Open Group, and may not be supported by your operating system for much longer.

If the termcap entry for your ancient esoteric terminal is wrong or incomplete, this module may either fill your screen with unintelligible gibberish, or drop back to a feature-free mode.

Eventually, support for Terminfo may also be added.

IO::Pager::Perl sets a global signal handler for SIGWINCH, this is the only way it can effectively detect and accommodate changes in terminal size. If you also need notification of this signal, the handler will trigger any callback assigned to the WINCH attribute of the "new" method.

IO::Pager::Perl checks the TERM and TERMCAP variables.

IO::Pager, Term::Cap, Term::ReadKey, termcap(5), stty(1), tput(1), less(1)

    Jerrad Pierce jpierce@cpan.org
    Jeff Weisberg - http://www.tcp4me.com

This software may be copied and distributed under the terms found in the Perl "Artistic License".

A copy of the "Artistic License" may be found in the standard Perl distribution.

2019-10-08 perl v5.34.0