App-ansicolumn
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/App/ansicolumn.pm view on Meta::CPAN
### --runlen
has '+runlen' => sub {
$_->runin = $_->runout = $_[1];
};
# for backward compatibility, would be deplicated
has run => '=i';
has '+run' => sub {
$_->runin = $_->runout = $_[1];
};
### --tabstop, --tabstyle
has [ qw(+tabstop +tabstyle) ] => sub {
my($name, $val) = map "$_", @_;
if ($val eq '') {
list_tabstyle();
exit;
}
Text::ANSI::Fold->configure($name => $val);
};
### --tabhead, --tabspace
use charnames ':loose';
has [ qw(+tabhead +tabspace) ] => sub {
my($name, $c) = map "$_", @_;
$c = charnames::string_vianame($c) || die "$c: invalid name\n"
if length($c) > 1;
Text::ANSI::Fold->configure($name => $c);
};
### -A, -T
has '+table_align' => sub {
if ($_->table_align = $_[1]) {
$_->table = $_[1];
}
};
has '+table_tabs' => sub {
if ($_->table_tabs = $_[1]) {
$_->table = $_->table_align = $_[1];
}
};
has TERM_SIZE => ;
has COLORHASH => default => { %DEFAULT_COLORMAP };
has COLORLIST => default => [];
has COLOR => ;
has BORDER => ;
} no Getopt::EX::Hashed;
sub list_tabstyle {
my %style = %Text::ANSI::Fold::TABSTYLE;
my $max = max map length, keys %style;
for my $name (sort keys %style) {
my($head, $space) = @{$style{$name}};
printf "%*s %s%s\n", $max, $name, $head, $space x 7;
}
}
sub perform {
my $obj = shift;
local @ARGV = decode_argv(@_);
$obj->getopt || pod2usage(2);
$obj->setup_options;
warn Dumper $obj if $obj->debug;
my @files = $obj->read_files(@ARGV ? @ARGV : '-') or return 1;
if ($obj->table) {
my @lines = map { @{$_->{data}} } @files;
$obj->table_out(@lines);
}
elsif ($obj->parallel) {
$obj->parallel_out(@files);
}
else {
$obj->nup_out(@files);
}
return 0
}
sub setup_options {
my $obj = shift;
## --parallel or @ARGV > 1
if ($obj->parallel //= @ARGV > 1) {
$obj->linestyle ||= 'wrap';
$obj->widen //= 1;
$obj->border //= '';
}
## --border takes optional border-style value
if (defined(my $border = $obj->border)) {
if ($border ne '') {
$obj->border_style = $border;
}
$obj->border = 1;
$obj->fillup //= 'pane';
}
## --linestyle
if ($obj->linestyle eq 'wordwrap') {
$obj->linestyle = 'wrap';
$obj->boundary = 'word';
}
## -P
if (defined $obj->page) {
$obj->widen = 1 if $obj->pane and not $obj->pane_width;
$obj->height ||= $obj->page || $obj->term_height - 1;
$obj->linestyle ||= 'wrap';
$obj->border //= 1;
$obj->fillup //= 'pane';
}
## -U
if ($obj->up) {
$obj->pane = $obj->up;
$obj->widen = 1;
view all matches for this distributionview release on metacpan - search on metacpan
( run in 4.576 seconds using v1.00-cache-2.02-grep-82fe00e-cpan-72ae3ad1e6da )