From 49b1d198b904f7658485889050df71bfedad4927 Mon Sep 17 00:00:00 2001 From: Pascal Rigaux Date: Thu, 20 Mar 2008 20:16:32 +0000 Subject: o handle displaying utf8 download progression in non-utf8 terminal (ie clean the full line when we can't be sure of the number of characters that will be displayed) --- urpm/download.pm | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'urpm/download.pm') diff --git a/urpm/download.pm b/urpm/download.pm index 9ccd2f2b..654ee7f3 100644 --- a/urpm/download.pm +++ b/urpm/download.pm @@ -5,6 +5,7 @@ package urpm::download; use strict; use urpm::msg; use urpm::util; +use bytes(); use Cwd; use Exporter; @@ -686,7 +687,13 @@ sub sync_logger { $text = N(" %s%% completed, speed = %s", $percent, $speed); } if (length($text) > $wchar) { $text = substr($text, 0, $wchar) } - print STDERR $text, " " x ($wchar - length($text)), "\r"; + if (bytes::length($text) < $wchar) { + # clearing more than needed in case the terminal is not handling utf8 and we have a utf8 string + print STDERR $text, " " x ($wchar - bytes::length($text)), "\r"; + } else { + # clearing all the line first since we can't really know the "length" of the string + print STDERR " " x $wchar, "\r", $text, "\r"; + } } elsif ($mode eq 'end') { print STDERR " " x $wchar, "\r"; } elsif ($mode eq 'error') { -- cgit v1.2.1