SVN: toys/rsget.pl: README RSGet/Line.pm RSGet/Main.pm

sparky sparky at pld-linux.org
Mon Nov 2 03:06:16 CET 2009


Author: sparky
Date: Mon Nov  2 03:06:16 2009
New Revision: 10923

Modified:
   toys/rsget.pl/README
   toys/rsget.pl/RSGet/Line.pm
   toys/rsget.pl/RSGet/Main.pm
Log:
- now will also work without Term::Size


Modified: toys/rsget.pl/README
==============================================================================
--- toys/rsget.pl/README	(original)
+++ toys/rsget.pl/README	Mon Nov  2 03:06:16 2009
@@ -5,6 +5,7 @@
   compare old with new.
 - Add commands: pause downloads, allow/don't allow captcha, clean done
   downloads, and more
+- File group support (first step for multiuser support)
 
 Planned features:
 - Multiuser support (may require major changes in the code).

Modified: toys/rsget.pl/RSGet/Line.pm
==============================================================================
--- toys/rsget.pl/RSGet/Line.pm	(original)
+++ toys/rsget.pl/RSGet/Line.pm	Mon Nov  2 03:06:16 2009
@@ -8,9 +8,25 @@
 use strict;
 use warnings;
 use RSGet::Tools;
-use Term::Size;
 set_rev qq$Id$;
 
+my $term_size_columns;
+my $term_size_rows;
+
+sub term_size
+{
+	local $SIG{__DIE__};
+	delete $SIG{__DIE__};
+	eval {
+		require Term::Size;
+		( $term_size_columns, $term_size_rows ) = Term::Size::chars();
+	};
+	$term_size_columns ||= $ENV{COLUMNS} || 80;
+	$term_size_rows ||= $ENV{LINES} || 0;
+
+	return $term_size_columns;
+}
+
 our %active;
 my %dead;
 our @dead;
@@ -109,11 +125,11 @@
 
 sub print_all_lines
 {
-	my ( $columns, $rows ) = Term::Size::chars;
+	term_size() unless $term_size_columns;
 	my $added = 0;
 	print_dead_lines();
-	$added += print_status_lines( $columns );
-	$added += print_active_lines( $columns );
+	$added += print_status_lines( $term_size_columns );
+	$added += print_active_lines( $term_size_columns );
 	return $added;
 }
 
@@ -189,8 +205,8 @@
 
 	$SIG{WINCH} = sub {
 		print "\033[2J\033[1;1H\n";
-		my ( $columns, $rows ) = Term::Size::chars;
-		my $start = $#dead - $rows;
+		term_size();
+		my $start = $term_size_rows ? $#dead - $term_size_rows : 0;
 		$start = 0 if $start < 0;
 		print join( "\n", @dead[($start..$#dead)] ), "\n";
 		update();

Modified: toys/rsget.pl/RSGet/Main.pm
==============================================================================
--- toys/rsget.pl/RSGet/Main.pm	(original)
+++ toys/rsget.pl/RSGet/Main.pm	Mon Nov  2 03:06:16 2009
@@ -83,8 +83,7 @@
 
 sub print_help
 {
-	require Term::Size;
-	my ( $columns, $rows ) = Term::Size::chars;
+	my $columns = RSGet::Line::term_size();
 	print "Usage: $0 [OPTIONS] [LIST FILE]\n";
 	print "Downloads files from services like RapidShare.\n\n";
 	print "Arguments are always mandatory.\n";


More information about the pld-cvs-commit mailing list