File Coverage

blib/lib/Term/Scroller.pm
Criterion Covered Total %
statement 133 136 97.7
branch 36 44 81.8
condition 26 40 65.0
subroutine 18 18 100.0
pod 3 3 100.0
total 216 241 89.6


line stmt bran cond sub pod time code
1             package Term::Scroller;
2              
3 5     5   897041 use 5.020;
  5         56  
4 5     5   34 use strict;
  5         10  
  5         98  
5 5     5   26 use warnings;
  5         5  
  5         148  
6              
7 5     5   36 use feature 'unicode_strings';
  5         7  
  5         876  
8              
9             our $VERSION = '1.1';
10              
11             =head1 NAME
12              
13             Term::Scroller - Display text in a scrolling viewport in your terminal
14              
15             =head1 SYNOPSIS
16              
17             use Term::Scroller;
18            
19             # Default options
20             my $scroll = Term::Scroller->new();
21             print $scroll "blah blah blah\n" for (1..100);
22             # You should always call the end() method when you're done
23             $scroll->end();
24              
25             # Some more options (limited window size, with a border)
26             $scroll = scroller(width => 40, height => 5, window => '-#-#-#-#');
27             print $scroll "beee daah booo\n" for (1..100);
28             $scroll->end();
29              
30             # See the rest of the documentation for more options!
31              
32             =head1 DESCRIPTION
33              
34             B provides you with a way to view a large stream of text
35             inside a small, scrolling viewport on your terminal. The size and borders of
36             the viewport/window can be customized along with a number of other control
37             options.
38              
39             For a command-line program that uses this to display the output of commands
40             see L.
41              
42             =cut
43              
44 5     5   620 use IO::Handle;
  5         6345  
  5         246  
45              
46 5     5   87 use Carp;
  5         14  
  5         293  
47 5     5   31 use Symbol qw(qualify_to_ref);
  5         10  
  5         246  
48 5     5   27 use Scalar::Util qw(openhandle);
  5         10  
  5         306  
49 5     5   30 use List::Util qw(any);
  5         10  
  5         529  
50              
51 5     5   2449 use IO::Pty;
  5         70234  
  5         259  
52 5     5   2622 use Term::ReadKey qw(GetTerminalSize);
  5         9985  
  5         6137  
53              
54             our @ISA = qw(IO::Pty);
55              
56             =head1 Methods
57              
58             =head2 new
59              
60             Returns a new scroller instance. The scroller is a filehandle
61             (actually an instance of L) where anything written to
62             it is displayed in the scrolling window. The scroller will sanitize any
63             cursor-related ANSI escape sequences so text that expects them to work might
64             look garbled, but at least it should be very difficult to escape or break the
65             window. color-related ANSI sequences are left untouched though so colored
66             text will still work inside the window.
67              
68             I
69              
70             The arguments to B are interpreted as a hash and can contain the
71             following options:
72              
73             =head3 Size & Styling Options
74              
75             =over 4
76              
77             =item * B
78              
79             Integer representing the maximum height (in lines) of the viewport. The window
80             will grow as more lines of input come in and start scrolling once it reaches
81             this height. (B: 10)
82              
83             =item * B
84              
85             Integer representing the maximum width (in columns) of the viewport. Input lines
86             will truncated at this width, not including ANSI escape sequences.
87             (B: the width of the connected terminal, or 80 if the width
88             couldn't be determined for some reason).
89              
90             =item * B
91              
92             Integer representing the width of tabs (in characters) when viewed in the
93             viewport. For consistent printing, tabs are replaced with this number of
94             spaces. (B: 4)
95              
96             =item * B