From: Peder Stray Date: Fri, 20 Aug 2021 11:53:04 +0000 (+0200) Subject: Update log2ansi to 1.11 X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=dca59137e708c6820fad6432a2197faf9bad2ae2;p=irssi-scripts.irssi.org.git Update log2ansi to 1.11 Added help options and support for more compessors --- diff --git a/scripts/log2ansi.pl b/scripts/log2ansi.pl index bdeaa1b..0680c15 100755 --- a/scripts/log2ansi.pl +++ b/scripts/log2ansi.pl @@ -8,13 +8,14 @@ use strict; use Getopt::Long; use Encode; +use Pod::Usage; use vars qw(%ansi %base %attr %old); use vars qw(@bols @nums @mirc @irssi @mc @mh @ic @ih @cn); use vars qw($class $oldclass); use vars qw{$VERSION %IRSSI}; -($VERSION) = '$Revision: 1.10 $' =~ / (\d+\.\d+) /; +($VERSION) = '$Revision: 1.11 $' =~ / (\d+\.\d+) /; %IRSSI = ( name => 'log2ansi', authors => 'Peder Stray', @@ -33,18 +34,35 @@ if (__PACKAGE__ =~ /^Irssi/) { my $opt_clear = 0; my $opt_html = 0; my $opt_utf8 = 0; +my $opt_help = 0; GetOptions( - 'clear!' => \$opt_clear, - 'html!' => \$opt_html, - 'utf8!' => \$opt_utf8, - ); + 'c|clear!' => \$opt_clear, + 'h|html!' => \$opt_html, + 'u|utf8!' => \$opt_utf8, + 'help' => sub { $opt_help = 1 }, + 'full-help' => sub { $opt_help = 2 }, + ) or pod2usage(2); + +# show some help if stdin is a tty and no files +$opt_help = 1 if !$opt_help && -t 0 && !@ARGV; + +pod2usage(-verbose => $opt_help, + -exitval => 0, + ) if $opt_help; for (@ARGV) { - if (/\.bz2$/) { + if (/\.xz$/) { + $_ = "unxz < '$_' |"; + } + elsif (/\.bz2$/) { $_ = "bunzip2 < '$_' |"; - } elsif (/\.gz$/) { - $_ = "gunzip < '$_' |"; + } + elsif (/\.gz$/) { + $_ = "gunzip < '$_' |"; + } + elsif (/\.lzma$/) { + $_ = "unlzma < '$_' |"; } } @@ -324,3 +342,71 @@ while (<>) { if ($opt_html) { print "\n"; } + +__END__ + +=head1 NAME + +log2ansi - Convert foo various color escape codes to ANSI (or strip them) + +=head1 SYNOPSIS + +B +[B<-c>|B<--clear>] +[B<-h>|B<--html>] +[B<-u>|B<--utf8>] +[B<--help>] +[I] + +=head1 OPTIONS + +=over + +=item B<-c>, B<--clear> + +Instructs B to clear all formatting and output plain text logs. + +=item B<-h>, B<--html> + +Instructs B to output a HTML fragment instead of ANSI text. + +The whole log will be wrapped in a div with class C, each line +of the log in a div with class C. Colors are wrapped in spans, +with a class name consisting of C or C, concatenated with the +color name, either C or C, or C, C, C, C, +C, C, or C prefixed with either C for light, or C for +dark. + +You have to include appropriate CSS yourself to get any colors at all +when viewing the log. + +=item B<-u>, B<--utf8> + +This forces output to be UTF-8, and does input decoding of UTF-8 with +fallback to ISO-8859-1. Use this if your input logs have mixed UTF-8 +and ISO-8859-1. + +=item B<--help>, B<--full-help> + +Show help, either just option descriptions or a full man page. + +=back + +=head1 DESCRIPTION + +Use B to convert logfiles from Irssi with internal escape +codes, mIRC color codes or ANSI escapes to plain text with ANSI +formatted color codes for viewing in a terminal. + +Use the B<--clear> option to strip all formatting escapes and output +just plain text. + +You can supply input on standard input, or as filenames on the command +line. Any file ending in B<.gz>, B<.bz2>, B<.xz> or B<.lzma> will be +uncompressed automatically before processing. + +=head1 AUTHORS + + Peder Stray + +=cut