pricecharts

track prices of consumer electronics
Log | Files | Refs | README

commit 7c66858a5de2f8f277a5c66aa5321ddce0210f3c
parent 5c1e4956b9124651f0956d4f44acf468c0441bc4
Author: Kyle Milz <kyle@getaddrinfo.net>
Date:   Thu, 12 Mar 2015 01:26:42 -0600

PriceChart: tighten trunc_line

Diffstat:
MPriceChart.pm | 12++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/PriceChart.pm b/PriceChart.pm @@ -125,22 +125,26 @@ sub get_log return $log; } +# +# make a possibly long line fit on a single line, with ellipses +# sub trunc_line { my $line = shift; my $prefix = shift || 0; my $front = shift || 0; - my ($wchar) = Term::ReadKey::GetTerminalSize(); - if (length($line) < ($wchar - $prefix - 3)) { + my ($term_width) = Term::ReadKey::GetTerminalSize(); + my $len = $term_width - $prefix - 3; + if (length($line) < $len) { return $line; } if ($front) { - my $chopped = substr($line, length($line) - ($wchar - $prefix - 3)); + my $chopped = substr($line, length($line) - $len); return "..." . $chopped; } - my $chopped = substr($line, 0, ($wchar - $prefix - 3)); + my $chopped = substr($line, 0, $len); return $chopped . "..."; }