X-Git-Url: http://git.shiar.nl/barcat.git/blobdiff_plain/571ed1a9a73129dff78c4d04333949605b91c273..37ae26f3382bb9f040399930cd5b1ee15a7cfba8:/reformat-podusage diff --git a/reformat-podusage b/reformat-podusage index cbb25cc..4fe82a3 100755 --- a/reformat-podusage +++ b/reformat-podusage @@ -1,27 +1,29 @@ #!/usr/bin/env perl use 5.014; use warnings; +use utf8; use open qw( :std :utf8 ); use re '/msx'; -our $VERSION = '1.00'; +our $VERSION = '1.01'; local $/ = undef; # slurp my $source = readline; my $pod = $source; $pod =~ s/^=over\K/ 25/; # indent options list +$pod =~ s/[BC]<([^>]+)>/$1/g; # unbolden $pod =~ s{ ^=item \h \N*\n\n \N*\n \K # first line (?: (?: ^=over .*? ^=back\n )? (?!=) \N*\n )* }{\n}g; # abbreviate options -$pod =~ s/[.,](?=\n)//g; # trailing punctuation $pod =~ s/^=item\ \K(?=--)/____/g; # align long options # abbreviate indicators $pod =~ s/\Q>.../s>/g; -$pod =~ s/<(?:number|count|seconds)>/N/g; -$pod =~ s//\Uchar$1/g; +$pod =~ s/I<(?:number|count|seconds)>/N/g; +$pod =~ s/I/\Uchar$1/g; $pod =~ s/\Q | /|/g; -$pod =~ s/(?/\U$1/g; # uppercase +$pod =~ s/I<([a-z]+)> (?![.,])/\U$1/g; # uppercase +$pod =~ s/[.,](?=\n)//g; # trailing punctuation require Pod::Usage; my $parser = Pod::Usage->new(USAGE_OPTIONS => { @@ -34,6 +36,16 @@ $parser->parse_string_document($pod); $usage =~ s/\n(?=\n\h)//msg; # strip space between items $usage =~ s/^\ \ \K____/ /g; # nbsp substitute +if (open my $logo, '<', 'mascot.txt') { + # append logo lines to top usage lines + my @ll = split /\n/, readline $logo; + my @ul = split /\n/, $usage, @ll + 1; + # centered in empty space on the second (longest) line + my $pad = (78 - 1 + length($ul[1]) - length($ll[0])) >> 1; + $ul[$_] .= (' ' x ($pad - length($ul[$_]))) . $ll[$_] for 0..$#ll; + $usage = join "\n", @ul; +} + if ($ARGV eq '-') { # custom formatted minimal usage text from pod document print $usage;