IO::Pager::Perl(3pm)

πŸ“¦
version 2.10 Β· 4 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– IO::Pager::Perl β€” User Contributed Perl Documentation πŸ’–

okay bestie, gather round, because this is IO::Pager::Perl and it is literally the moment. πŸ’…


✨ NAME ✨

IO::Pager::Perl β€” page text a screenful at a time, like more or less but make it yours 🫢


🌸 SYNOPSIS 🌸

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();

πŸ¦‹ DESCRIPTION πŸ¦‹

So this is a module for paging through text one screenful at a time. It supports the features you expect using the shortcuts you expect. no cap. πŸ’―

IO::Pager::Perl is an enhanced fork of Term::Pager. glow-up era fr fr ✨


πŸ‘‘ USAGE πŸ‘‘

πŸŽ€ Create the Pager πŸŽ€

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

If you don't specify any options, sensible default values will be used. The following options are recognized, and shown with the default value:

  • rows =>25? β€” 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.
  • cols =>80? β€” 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.
  • speed =>38400? β€” 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.
  • eof =>0 β€” exit at end of file. bye bestie πŸ‘‹
  • fold =>1 β€” fold long lines with Text::Wrap.
  • lineNo =>0 β€” if true, line numbering is added to the output.
  • pause =>0 β€” 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.
  • raw =>0 β€” 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.
  • scrollBar =>0 β€” --scrollbar β€” display an interactive scrollbar in the right-most column. πŸ“œβœ¨
  • squeeze =>0 β€” collapse multiple blank lines into one.
  • statusCol =>0 β€” add a column with markers indicating which row match a search expression.
  • visualBell =>0 β€” flash the screen when beeping. lowkey iconic 🌈

πŸ”‘ Accessors

There are accessors for all of the above properties, however those for rows, cols, speed, fold and squeeze are read only. (they said look, don't touch πŸ’…)

#Is visualBell set?
$t->visualBell();

#Enable line numbering
$t->lineNo(1);

πŸ“ Adding Text πŸ“

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.

🧚 Callback

You can also pass a code reference to the text attribute of the constructor which will be called when reaching the "end of file"; consequently, it is not possible to set the eof flag to exit at end of file if doing so.

$t->new( text=>sub{ } ); #eof=>0 is implied

Alternatively, you may supply a reference to a two element array. The first is an initial chunk of text to load, and the second the callback. bestie this is so clever 🫢

#Fibonacci
my($m, $n)=(1,1);
$t->new( text=> ["1\n", sub{ ($m,$n)=($n,$m+$n); return "$n\n"} ] );

🌈 User Interface 🌈

There are multiple special bookmarks (marks) that can be used in navigation.

  • ^ β€” Beginning of file
  • $ β€” End of file
  • ' β€” Previous location
  • " β€” List user-created marks

"add_text" will automatically create special numeric marks when it encounters a special character sequence, allowing the user to jump to predetermined points in the buffer. Sequence that match the following regular expression

/\cF\c]\cL\cE \[(\d+)\// #e.g; ^F^]^L^E [3/4]

will have marks matching $1 created that point at the line of the buffer the sequence occurs on. slay πŸŽ€


πŸ’œ CUSTOMIZATION πŸ’œ

⭐ add_func

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 mappings are listed below, and lengthier descriptions are available in tp.

πŸ’– General

  • &help β€” "h" or "H"
  • &close β€” "q" or "Q" or ":q" or ":Q"
  • &refresh β€” "r" or "C-l" or "C-R"
  • &flush_buffer β€” "R"
  • &write_buffer β€” ":w"
  • &open_file β€” ":e"
  • &downline β€” "ENTER" or "e" or "j" or "J" or "C-e" or "C-n" or "down arrow"
  • &downhalf β€” "d" or "C-d"
  • &downpage β€” "SPACE" "f" or "z" or "C-f" or "C-v" or "M-space" or "PgDn"
  • &uppage β€” "b" or "w" or "C-b" or "M-v" or "PgUp"
  • &uphalf β€” "u" or "C-u"
  • &upline β€” "k" or "y" or "K" or "Y" or "C-K" or "C-P" or "C-Y" or "up arrow"
  • &to_bott β€” "G" or "$" or ">" or "M->" or "End"
  • &to_top β€” "g" or "<" or "M-<"
  • &tab_left β€” "left arrow"
  • &shift_left β€” "S-left arrow"
  • &tab_right β€” "right arrow"
  • &shift_right β€” "S-right arrow"
  • &next_file β€” ":n" or "S-M-right arrow"
  • &prev_file β€” ":p" or "S-M-left arrow"

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

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

if the value for that key is true.

🌸 Bookmarks

  • &save_mark β€” "m" or "Ins"
  • &goto_mark β€” "'"
  • &search β€” /
  • &hcraes β€” ?
  • &next_match β€” n or P
  • &prev_match β€” p or N
  • &grep β€” &

πŸŽ€ Options

  • &toggle_num β€” #
  • &toggle_fold β€” S
  • &toggle_raw β€” C

🌟 I18N

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. no cap πŸ‘‘

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('minihelp', "<h> help");

Current text elements available for customization are:

404        - search text not found dialog
continue   - text to display at the bottom of the help dialog
help       - help dialog text, a list of keys and their functions
minihelp   - basic instructions displayed at the bottom of the screen
status     - brief message to include in the status line
top        - start of file prompt
bottom     - end of file prompt
searchwrap - message that pager is about to loop for more matches

prompt is intended for sharing short messages not worthy of a dialog e.g; when debugging. You will need to call the "status" method after setting it to refresh the status line of the display, then void prompt and call "status" 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.


πŸ’€ CAVEATS πŸ’€

🐧 UN*X

This modules currently only works in a UN*X-like environment. bestie if you're on Windows... it's giving limitation 😭

πŸƒ Performance

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.

πŸ“Ÿ Termcap

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.

🚨 Signals

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.

WINCH is not available on Windows. You will need to manually refresh your screen ^L if you resize the terminal in Windows to clean up the text however, this will not change the size of the pager itself.


🌍 ENVIRONMENT 🌍

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


πŸ” SEE ALSO πŸ”

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


πŸ‘‘ AUTHORS πŸ‘‘

Jerrad Pierce jpierce@cpan.org

Jeff Weisberg - http://www.tcp4me.com

πŸ“œ LICENSE πŸ“œ

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.


okay that's the whole page bestie, you ate it up πŸ’…βœ¨ This was perl v5.30.3, dated 2020-11-07, and it's the IO::Pager::Perl(3pm) manual β€” periodt. πŸŽ€πŸ¦‹πŸ’–

πŸ“¦ where this page comes from