3 # a quick-n-dirty cmdline pager for fefes blog
4 # navigate with 'n', 'p' and 'q'
5 # startup options: --color
6 # by Daniel Borkmann, borkmann@gnumaniacs.org
16 require HTML
::TreeBuilder
;
17 require HTML
::FormatText
;
21 my ($columns, $rows) = Term
::Size
::chars
*STDOUT
{IO
};
22 my $agent = LWP
::UserAgent
->new;
23 my $parser = XML
::RSS
->new;
24 my $formatter = HTML
::FormatText
->new( leftmargin
=> 0
25 , rightmargin
=> $columns - 2 );
26 my $rawrss = HTTP
::Request
->new(GET
=> 'http://blog.fefe.de/rss.xml?html');
37 $with_colors = 1 if (defined($ARGV[0]) && $ARGV[0] eq "--color");
38 $agent->default_header( 'Accept-Language' => 'en-US'
39 , 'Accept-Charset' => 'utf-8'
40 , 'Accept' => '*/*' );
41 $agent->agent('Fnord-Pager 1.0');
44 $parser->parse($agent->request($rawrss)->content);
48 my $ref = scalar(@links);
50 $link = "http://blog.fefe.de".$link if ($link =~ m/^\/\?ts
=/);
55 open(TTY
, "+</dev/tty") or die "No tty: $!";
56 system "stty cbreak </dev/tty >/dev/tty 2>&1";
58 $max = scalar(@
{$parser->{'items'}});
59 for (my $elem = 0; $elem < $max; )
61 my ($cmd, $html, $count, $lsize);
62 my $item = $parser->{'items'}[$elem];
63 my $content = $item->{'description'};
71 $content =~ s/<a\s*href=\"(.*?)\">(.*?)<\/a>/"$2 \[".cite
($1)."\]"/eg
;
73 $lsize = scalar(@links);
74 $content = $content."\n<ul>";
75 foreach ($count = 0; $count < $lsize; $count++)
77 $content = $content."<li>\[$count\] ".shift(@links)."</li>";
79 $content = $content."</ul>";
80 $content = "<html><body>".$content."</body></html>";
82 $html = HTML
::TreeBuilder
->new_from_content($content);
83 $content = $formatter->format($html);
84 $content = encode
('utf-8', $content);
86 if ($with_colors == 1) {
87 print colored
['bold '.$colors[$color].' on_black'], "\r".$content;
88 print colored
['reset'], "\n\n";
90 print "\r".$content."\n\n";
93 $color = ($color + 1) % scalar(@colors);
99 } elsif ($cmd eq 'n') {
101 $elem = $max - 1 if ($elem == $max);
102 }elsif ($cmd eq 'p') {
104 $elem = 0 if ($elem < 0);
108 system "stty -cbreak </dev/tty >/dev/tty 2>&1";