Alter the default wrap width for LDIF to expand to the terminal size,
authorMahlon E. Smith <mahlon@laika.com>
Fri, 15 Mar 2013 10:02:19 -0700
changeset 49 57df728cdb77
parent 48 fe27dfe5179e
child 50 21ba5eb5c2fc
Alter the default wrap width for LDIF to expand to the terminal size, with an optional rc file override.
shelldap
--- a/shelldap	Fri Mar 15 10:02:18 2013 -0700
+++ b/shelldap	Fri Mar 15 10:02:19 2013 -0700
@@ -564,17 +564,28 @@
 	my $self	 = shift;
 	my $use_temp = shift;
 
+	# find the terminal width
+	#
+	my $wrap = $conf->{'wrap'};
+	eval {
+		my $rows;
+		my $term = Term::ReadLine->new( 1 );
+		( $rows, $wrap ) = $term->get_screen_size() unless $wrap;
+	};
+	$wrap ||= 78;
+
 	# create tmpfile and link ldif object with it
+	#
 	if ( $use_temp ) {
 		my ( undef, $fname ) =
 		  File::Temp::tempfile( 'shelldap_XXXXXXXX', DIR => '/tmp', UNLINK => 1 );
-		$self->{'ldif'}	   = Net::LDAP::LDIF->new( $fname, 'w', sort => 1 );
+		$self->{'ldif'}	      = Net::LDAP::LDIF->new( $fname, 'w', sort => 1, wrap => $wrap );
 		$self->{'ldif_fname'} = $fname;
 	}
 
 	# ldif -> stdout
 	else {
-		$self->{'ldif'} = Net::LDAP::LDIF->new( \*STDOUT, 'w', sort => 1 );
+		$self->{'ldif'} = Net::LDAP::LDIF->new( \*STDOUT, 'w', sort => 1, wrap => $wrap );
 	}
 
 	return $self->{'ldif'};