From: Jay Hannah Date: Thu, 22 Jan 2009 01:45:16 +0000 (+0000) Subject: Text::SimpleTable's now go as wide as $ENV{COLUMNS} X-Git-Tag: 5.8000_05~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=39fc2ce1e456c4e2a272204aa8fe67896984b3a6 Text::SimpleTable's now go as wide as $ENV{COLUMNS} Patch written by Oleg Kostyuk --- diff --git a/Changes b/Changes index ee2897b..5efde8e 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,8 @@ # This file documents the revision history for Perl extension Catalyst. 5.8000_05 + - Text::SimpleTable's go as wide as $ENV{COLUMNS} (jhannah) + Patch written by Oleg Kostyuk - Improve docs for visit (mateu) - Add docs for finalize hook (dhoss) - Added ru/ua translations to error page diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index 4f92467..f3df124 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -989,7 +989,8 @@ EOF my @plugins = map { "$_ " . ( $_->VERSION || '' ) } $class->registered_plugins; if (@plugins) { - my $t = Text::SimpleTable->new(74); + my $column_width = Catalyst::Utils::term_width() - 6; + my $t = Text::SimpleTable->new($column_width); $t->row($_) for @plugins; $class->log->debug( "Loaded plugins:\n" . $t->draw . "\n" ); } @@ -1021,7 +1022,8 @@ EOF $class->setup_components; if ( $class->debug ) { - my $t = Text::SimpleTable->new( [ 63, 'Class' ], [ 8, 'Type' ] ); + my $column_width = Catalyst::Utils::term_width() - 8 - 9; + my $t = Text::SimpleTable->new( [ $column_width, 'Class' ], [ 8, 'Type' ] ); for my $comp ( sort keys %{ $class->components } ) { my $type = ref $class->components->{$comp} ? 'instance' : 'class'; $t->row( $comp, $type ); @@ -2617,6 +2619,8 @@ obra: Jesse Vincent omega: Andreas Marienborg +Oleg Kostyuk + phaylon: Robert Sedlacek rafl: Florian Ragwitz diff --git a/lib/Catalyst/DispatchType/Chained.pm b/lib/Catalyst/DispatchType/Chained.pm index fcb21ca..71a8fd3 100644 --- a/lib/Catalyst/DispatchType/Chained.pm +++ b/lib/Catalyst/DispatchType/Chained.pm @@ -5,6 +5,7 @@ extends 'Catalyst::DispatchType'; use Text::SimpleTable; use Catalyst::ActionChain; +use Catalyst::Utils; use URI; has _endpoints => ( @@ -67,9 +68,10 @@ sub list { return unless $self->_endpoints; + my $column_width = Catalyst::Utils::term_width() - 35 - 9; my $paths = Text::SimpleTable->new( - [ 35, 'Path Spec' ], [ 36, 'Private' ] - ); + [ 35, 'Path Spec' ], [ 36, 'Private' ], [ $column_width, 'Private' ] + ); my $has_unattached_actions; my $unattached_actions = Text::SimpleTable->new( diff --git a/lib/Catalyst/DispatchType/Path.pm b/lib/Catalyst/DispatchType/Path.pm index 93d300a..d58f1fd 100644 --- a/lib/Catalyst/DispatchType/Path.pm +++ b/lib/Catalyst/DispatchType/Path.pm @@ -4,6 +4,7 @@ use Moose; extends 'Catalyst::DispatchType'; use Text::SimpleTable; +use Catalyst::Utils; use URI; has _paths => ( @@ -35,7 +36,10 @@ Debug output for Path dispatch points sub list { my ( $self, $c ) = @_; - my $paths = Text::SimpleTable->new( [ 35, 'Path' ], [ 36, 'Private' ] ); + my $column_width = Catalyst::Utils::term_width() - 35 - 9; + my $paths = Text::SimpleTable->new( + [ 35, 'Path' ], [ $column_width, 'Private' ] + ); foreach my $path ( sort keys %{ $self->_paths } ) { my $display_path = $path eq '/' ? $path : "/$path"; foreach my $action ( @{ $self->_paths->{$path} } ) { diff --git a/lib/Catalyst/DispatchType/Regex.pm b/lib/Catalyst/DispatchType/Regex.pm index 4d8d28a..1ffa932 100644 --- a/lib/Catalyst/DispatchType/Regex.pm +++ b/lib/Catalyst/DispatchType/Regex.pm @@ -4,6 +4,7 @@ use Moose; extends 'Catalyst::DispatchType::Path'; use Text::SimpleTable; +use Catalyst::Utils; use Text::Balanced (); has _compiled => ( @@ -35,7 +36,8 @@ Output a table of all regex actions, and their private equivalent. sub list { my ( $self, $c ) = @_; - my $re = Text::SimpleTable->new( [ 35, 'Regex' ], [ 36, 'Private' ] ); + my $column_width = Catalyst::Utils::term_width() - 35 - 9; + my $re = Text::SimpleTable->new( [ 35, 'Regex' ], [ $column_width, 'Private' ] ); for my $regex ( @{ $self->_compiled } ) { my $action = $regex->{action}; $re->row( $regex->{path}, "/$action" ); diff --git a/lib/Catalyst/Dispatcher.pm b/lib/Catalyst/Dispatcher.pm index 3cb06ea..b0b3606 100644 --- a/lib/Catalyst/Dispatcher.pm +++ b/lib/Catalyst/Dispatcher.pm @@ -10,6 +10,7 @@ use Catalyst::Action; use Catalyst::ActionContainer; use Catalyst::DispatchType::Default; use Catalyst::DispatchType::Index; +use Catalyst::Utils; use Text::SimpleTable; use Tree::Simple; use Tree::Simple::Visitor::FindByPath; @@ -583,10 +584,9 @@ sub setup_actions { return unless $c->debug; + my $column_width = Catalyst::Utils::term_width() - 20 - 36 - 12; my $privates = Text::SimpleTable->new( - [ 20, 'Private' ], - [ 36, 'Class' ], - [ 12, 'Method' ] + [ 20, 'Private' ], [ 36, 'Class' ], [ $column_width, 'Method' ] ); my $has_private = 0; diff --git a/lib/Catalyst/Stats.pm b/lib/Catalyst/Stats.pm index 247e1bd..615cde1 100644 --- a/lib/Catalyst/Stats.pm +++ b/lib/Catalyst/Stats.pm @@ -3,6 +3,7 @@ package Catalyst::Stats; use Moose; use Time::HiRes qw/gettimeofday tv_interval/; use Text::SimpleTable (); +use Catalyst::Utils; use Tree::Simple qw/use_weak_refs/; use Tree::Simple::Visitor::FindByUID; @@ -88,7 +89,8 @@ sub elapsed { sub report { my $self = shift; - my $t = Text::SimpleTable->new( [ 62, 'Action' ], [ 9, 'Time' ] ); + my $column_width = Catalyst::Utils::term_width() - 9 - 13; + my $t = Text::SimpleTable->new( [ $column_width, 'Action' ], [ 9, 'Time' ] ); my @results; $self->traverse( sub { diff --git a/lib/Catalyst/Utils.pm b/lib/Catalyst/Utils.pm index 13c2a02..07c2058 100644 --- a/lib/Catalyst/Utils.pm +++ b/lib/Catalyst/Utils.pm @@ -19,6 +19,8 @@ See L. =head1 DESCRIPTION +Catalyst Utilities. + =head1 METHODS =head2 appprefix($class) @@ -334,6 +336,45 @@ sub env_value { return; } +=head2 term_width + +Try to guess terminal width to use with formatting of debug output + +All you need to get this work, is: + +1) Install Term::Size::Any, or + +2) Export $COLUMNS from your shell. + +(Warning to bash users: 'echo $COLUMNS' may be showing you the bash +variable, not $ENV{COLUMNS}. 'export COLUMNS=$COLUMNS' and you should see +that 'env' now lists COLUMNS.) + +As last resort, default value of 80 chars will be used. + +=cut + +my $_term_width; + +sub term_width { + return $_term_width if $_term_width; + + my $width = eval ' + use Term::Size::Any; + my ($columns, $rows) = Term::Size::Any::chars; + return $columns; + '; + + if ($@) { + $width = $ENV{COLUMNS} + if exists($ENV{COLUMNS}) + && $ENV{COLUMNS} =~ m/^\d+$/; + } + + $width = 80 unless ($width && $width >= 80); + return $_term_width = $width; +} + =head1 AUTHORS Catalyst Contributors, see Catalyst.pm