From: Guillermo Roditi Date: Sat, 8 Aug 2009 21:54:04 +0000 (+0000) Subject: make debug output prettier with large widths X-Git-Tag: 5.80008~32 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=48d435ba6a0925260fd58c8c18ff425e99708eae;hp=5e2186c55ff39ff02307a276806f7fd47c13f8d2 make debug output prettier with large widths --- diff --git a/Changes b/Changes index f984fc2..433c6d1 100644 --- a/Changes +++ b/Changes @@ -18,6 +18,8 @@ known issues with 5.8.3, and nobody is prepared to fix / support perl older than 5.8.6 any more. Patches to regain compatibility to older perls would be welcome. + - Debug output uses dynamic column sizing to create more readable output + when using a larger $ENV{COLUMNS} setting. (groditi) New features: - private_path method for Catalyst::Action + docs + tests (groditi) diff --git a/lib/Catalyst/DispatchType/Chained.pm b/lib/Catalyst/DispatchType/Chained.pm index ba488df..8446173 100644 --- a/lib/Catalyst/DispatchType/Chained.pm +++ b/lib/Catalyst/DispatchType/Chained.pm @@ -80,14 +80,16 @@ sub list { return unless $self->_endpoints; - my $column_width = Catalyst::Utils::term_width() - 35 - 9; + my $avail_width = Catalyst::Utils::term_width() - 9; + my $col1_width = ($avail_width * .50) < 35 ? 35 : int($avail_width * .50); + my $col2_width = $avail_width - $col1_width; my $paths = Text::SimpleTable->new( - [ 35, 'Path Spec' ], [ $column_width, 'Private' ], + [ $col1_width, 'Path Spec' ], [ $col2_width, 'Private' ], ); my $has_unattached_actions; my $unattached_actions = Text::SimpleTable->new( - [ 35, 'Private' ], [ $column_width, 'Missing parent' ], + [ $col1_width, 'Private' ], [ $col2_width, 'Missing parent' ], ); ENDPOINT: foreach my $endpoint ( diff --git a/lib/Catalyst/DispatchType/Path.pm b/lib/Catalyst/DispatchType/Path.pm index 95367ac..545e607 100644 --- a/lib/Catalyst/DispatchType/Path.pm +++ b/lib/Catalyst/DispatchType/Path.pm @@ -47,9 +47,11 @@ Debug output for Path dispatch points sub list { my ( $self, $c ) = @_; - my $column_width = Catalyst::Utils::term_width() - 35 - 9; + my $avail_width = Catalyst::Utils::term_width() - 9; + my $col1_width = ($avail_width * .50) < 35 ? 35 : int($avail_width * .50); + my $col2_width = $avail_width - $col1_width; my $paths = Text::SimpleTable->new( - [ 35, 'Path' ], [ $column_width, 'Private' ] + [ $col1_width, 'Path' ], [ $col2_width, 'Private' ] ); foreach my $path ( sort keys %{ $self->_paths } ) { my $display_path = $path eq '/' ? $path : "/$path"; diff --git a/lib/Catalyst/DispatchType/Regex.pm b/lib/Catalyst/DispatchType/Regex.pm index 11a9cbf..0d6da04 100644 --- a/lib/Catalyst/DispatchType/Regex.pm +++ b/lib/Catalyst/DispatchType/Regex.pm @@ -47,8 +47,12 @@ Output a table of all regex actions, and their private equivalent. sub list { my ( $self, $c ) = @_; - my $column_width = Catalyst::Utils::term_width() - 35 - 9; - my $re = Text::SimpleTable->new( [ 35, 'Regex' ], [ $column_width, 'Private' ] ); + my $avail_width = Catalyst::Utils::term_width() - 9; + my $col1_width = ($avail_width * .50) < 35 ? 35 : int($avail_width * .50); + my $col2_width = $avail_width - $col1_width; + my $re = Text::SimpleTable->new( + [ $col1_width, 'Regex' ], [ $col2_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 e90cdc1..9d2ae4a 100644 --- a/lib/Catalyst/Dispatcher.pm +++ b/lib/Catalyst/Dispatcher.pm @@ -615,9 +615,15 @@ sub setup_actions { sub _display_action_tables { my ($self, $c) = @_; - my $column_width = Catalyst::Utils::term_width() - 20 - 36 - 12; + my $avail_width = Catalyst::Utils::term_width() - 12; + my $col1_width = ($avail_width * .25) < 20 ? 20 : int($avail_width * .25); + my $col2_width = ($avail_width * .50) < 36 ? 36 : int($avail_width * .50); + my $col3_width = $avail_width - $col1_width - $col2_width; + $c->log->debug("col1: $col1_width"); + $c->log->debug("col2: $col2_width"); + $c->log->debug("col3: $col3_width"); my $privates = Text::SimpleTable->new( - [ 20, 'Private' ], [ 36, 'Class' ], [ $column_width, 'Method' ] + [ $col1_width, 'Private' ], [ $col2_width, 'Class' ], [ $col3_width, 'Method' ] ); my $has_private = 0;