[Po4a-commits] po4a/lib/Locale/Po4a Common.pm,1.4,1.5

Martin Quinson po4a-devel@lists.alioth.debian.org
Thu, 03 Mar 2005 09:58:35 +0000


Update of /cvsroot/po4a/po4a/lib/Locale/Po4a
In directory haydn:/tmp/cvs-serv23350

Modified Files:
	Common.pm 
Log Message:
Wrap to column of terminal size

Index: Common.pm
===================================================================
RCS file: /cvsroot/po4a/po4a/lib/Locale/Po4a/Common.pm,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- Common.pm	3 Mar 2005 09:49:20 -0000	1.4
+++ Common.pm	3 Mar 2005 09:58:32 -0000	1.5
@@ -32,6 +32,17 @@
 use Locale::gettext;
 use Text::WrapI18N qw(wrap $columns);
 
+sub setcolumns {
+    eval qq{
+	# won't work on windows, at least.
+	use Term::ReadKey qw(GetTerminalSize);
+	($columns) = GetTerminalSize();
+    };
+    if ($@) {
+	$columns = $ENV{'COLUMNS'} || 80;
+    }
+}
+
 sub min {
     return $_[0] < $_[1] ? $_[0] : $_[1];
 }
@@ -69,7 +80,8 @@
 sub wrap_msg {
     my $msg = shift;
     my @args = @_;
-
+    
+    setcolumns();
     return wrap("", "", sprintf($msg, @args))."\n";
 }
 
@@ -84,6 +96,7 @@
     my ($mod, $msg) = (shift, shift);
     my @args = @_;
 
+    setcolumns();
     $mod .= ": ";
     my $spaces = " " x min(length($mod), 15);
     return wrap($mod, $spaces, sprintf($msg, @args))."\n";
@@ -101,6 +114,7 @@
     my ($ref, $mod, $msg) = (shift, shift, shift);
     my @args = @_;
 
+    setcolumns();
     if (!$mod) {
 	# If we don't get a module name, show the message like wrap_mod does
 	return wrap_mod($ref, $msg, @args);