Skip to content

Commit 462d7cc

Browse files
Add some error handling around tput
We end up getting a lot of bug reports due to broken tput installations. This will wrapper tput and keep errors to a minimum
1 parent 03c386e commit 462d7cc

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

diff-so-fancy

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ my $VERSION = "1.2.7";
44

55
#################################################################################
66

7+
use 5.010; # Require Perl 5.10 for 'state' variables
78
use File::Spec; # For catdir
89
use File::Basename; # For dirname
910
use Encode; # For handling UTF8 stuff
@@ -588,7 +589,18 @@ sub trim {
588589
# Print a line of em-dash or line-drawing chars the full width of the screen
589590
sub horizontal_rule {
590591
my $color = $_[0] || "";
591-
my $width = $ruler_width || `tput cols`;
592+
593+
# Make width static so we only calculate it once
594+
state $width;
595+
if (!$width) {
596+
my $tput = `tput cols 2>1`;
597+
if (!$tput) {
598+
print color('orange') . "Warning: `tput cols` did not return numeric input" . color('reset') . "\n";
599+
$tput = 80;
600+
}
601+
602+
$width = $ruler_width || $tput;
603+
}
592604

593605
if (is_windows()) {
594606
$width--;

0 commit comments

Comments
 (0)