mirror of
https://github.com/erkin/ponysay.git
synced 2024-12-01 16:27:58 +01:00
Revert "Merge pull request #54 from spider-mario/master"
Error at line 29 This reverts commit39341e46e6
, reversing changes made to4e1655bc0b
.
This commit is contained in:
parent
39341e46e6
commit
e928a02e8a
1 changed files with 52 additions and 21 deletions
|
@ -1,4 +1,4 @@
|
||||||
#!/usr/bin/env perl
|
#!/usr/bin/perl
|
||||||
|
|
||||||
# ponysaylist
|
# ponysaylist
|
||||||
# Prints a list of ponies in columns
|
# Prints a list of ponies in columns
|
||||||
|
@ -9,32 +9,63 @@
|
||||||
# Author: Mattias Andrée, maandree@kth.se
|
# Author: Mattias Andrée, maandree@kth.se
|
||||||
|
|
||||||
|
|
||||||
use strict;
|
$first = 1;
|
||||||
use warnings;
|
$scrw = 1;
|
||||||
use utf8;
|
$maxw = 1;
|
||||||
use feature qw(say);
|
|
||||||
use integer;
|
|
||||||
use List::Util qw(max);
|
|
||||||
|
|
||||||
my $scrw = shift @ARGV;
|
foreach $arg (@ARGV)
|
||||||
|
{
|
||||||
for (@ARGV) {
|
|
||||||
# Format names from ponyies names
|
# Format names from ponyies names
|
||||||
s/(?<=[a-z])(?=[A-Z])/ /;
|
$arg =~ s/([a-z])([A-Z])/\1 \2/;
|
||||||
s/_(.*)/\t($1)/;
|
#$arg =~ s/_(.*)/\t(\1)/; ## Incompatible with `ponysay -L`
|
||||||
|
|
||||||
|
if ($first == 1)
|
||||||
|
{ $first = 0;
|
||||||
|
$scrw = $arg;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{ $w = length $arg;
|
||||||
|
$maxw = $w if ($w > $maxw);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
my $maxw = max map {length} @ARGV;
|
$cols = int (($scrw + 2) / ($maxw + 2));
|
||||||
|
$cols = 1 if ($cols < 1);
|
||||||
|
|
||||||
my $cols = max 1, (($scrw + 2) / ($maxw + 2));
|
|
||||||
|
|
||||||
my @list = map {sprintf "%-${maxw}s", $_} @ARGV;
|
@list = ();
|
||||||
|
|
||||||
my $rows = (@list + $cols - 1) / $cols;
|
$first = 1;
|
||||||
|
$items = 0;
|
||||||
my @rowlist;
|
foreach $arg (@ARGV)
|
||||||
for my $i (0 .. $#list) {
|
{
|
||||||
push @{$rowlist[$i % $rows]}, $list[$i];
|
if ($first == 1)
|
||||||
|
{ $first = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{ $ws = $maxw - (length $arg);
|
||||||
|
push @list, $arg.(" "x$ws);
|
||||||
|
$items += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$rows = int (($items + $cols - 1) / $cols);
|
||||||
|
$i = 0;
|
||||||
|
@rowlist = ();
|
||||||
|
|
||||||
|
while ($i < $items)
|
||||||
|
{ $row = 0;
|
||||||
|
while (($row < $rows) and ($i < $items))
|
||||||
|
{
|
||||||
|
$rowlist[$row] .= " " unless ($i < $rows);
|
||||||
|
$rowlist[$row] .= $list[$i];
|
||||||
|
$row += 1;
|
||||||
|
$i += 1;
|
||||||
|
} }
|
||||||
|
|
||||||
|
foreach $row (@rowlist)
|
||||||
|
{
|
||||||
|
print $row."\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
say join ' ', @$_ for @rowlist;
|
|
||||||
|
|
Loading…
Reference in a new issue