Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Don't invoke tput if --columns is passed #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions nowrap
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,10 @@ use open ':locale';
my $TABSTOP = 8;
my $ESCAPE_SEQUENCE_PATTERN = qr/(\e\[\d*(;\d+)*m)/;

my $columns = `tput cols`;
chomp($columns);
my $isWrap = 0;
my $indentString = '';
my $indentLength = 0;

if ($columns and $ENV{TERM} eq "cygwin") {
# use one less than the number of columns when running on Windows under
# cygwin. Thanks to Ingo Karkat: https://github.com/goodell/nowrap/issues/2
--$columns;
}

$columns = 80 unless $columns;
my $columns;

GetOptions(
"help" => \&print_usage_and_exit,
Expand All @@ -108,6 +99,19 @@ GetOptions(
},
) or die "unable to parse options, stopped";

unless (defined $columns) {
$columns = `tput cols`;
chomp($columns);

if ($columns and $ENV{TERM} eq "cygwin") {
# use one less than the number of columns when running on Windows under
# cygwin. Thanks to Ingo Karkat: https://github.com/goodell/nowrap/issues/2
--$columns;
}

$columns = 80 unless $columns;
}

if ($columns < $indentLength + 1) {
die "--columns too small to accommodate --indent-string and any characters, stopped";
}
Expand Down
24 changes: 14 additions & 10 deletions script/nowrap.pl
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,10 @@
my $TABSTOP = 8;
my $ESCAPE_SEQUENCE_PATTERN = qr/(\e\[\d*(;\d+)*m)/;

my $columns = `tput cols`;
chomp($columns);
my $isWrap = 0;
my $indentString = '';
my $indentLength = 0;

if ($columns and $ENV{TERM} eq "cygwin") {
# use one less than the number of columns when running on Windows under
# cygwin. Thanks to Ingo Karkat: https://github.com/goodell/nowrap/issues/2
--$columns;
}

$columns = 80 unless $columns;
my $columns;

GetOptions(
"help" => \&print_usage_and_exit,
Expand All @@ -62,6 +53,19 @@
},
) or die "unable to parse options, stopped";

unless (defined $columns) {
$columns = `tput cols`;
chomp($columns);

if ($columns and $ENV{TERM} eq "cygwin") {
# use one less than the number of columns when running on Windows under
# cygwin. Thanks to Ingo Karkat: https://github.com/goodell/nowrap/issues/2
--$columns;
}

$columns = 80 unless $columns;
}

if ($columns < $indentLength + 1) {
die "--columns too small to accommodate --indent-string and any characters, stopped";
}
Expand Down
24 changes: 24 additions & 0 deletions tests/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,27 @@ else
exit 1
fi

# make sure nowrap doesn't invoke 'tput' if '-c' is passed
(
# TERM is the one that matters (breaks 'tput cols'), but COLUMNS and LINES
# are to avoid any clever fallback that might get added to nowrap in the
# future
unset TERM
unset COLUMMS
unset LINES

# send stderr to /dev/null because nohup always warns about redirecting its output
nohup ${NOWRAP} --columns=72 tc0.in 2>/dev/null
status=$?
if [[ $status -ne 0 ]] ; then
echo "ERROR: non-zero exit code ($status)"
fi

if $DIFF tc0.expected nohup.out ; then
:
else
echo "ERROR: nohup run failed (expected != output)"
fi

rm -f nohup.out
)