perl - 为线程的进度制作漂亮的控制台输出
perl - make beautiful console output for progress of threads
我的所有线程都想将它们的进度打印到同一行终端。我不能让他们选择不同的线路。我该如何处理? (linux & windows,如果可能的话)
编辑:
我尝试了两种变体:
1.
当我打印 '\n' 时,行下降,\b 不删除 \n 字符:
if ( !($x % 10) )
{
local $| = 1; # Or use IO::Handle; STDOUT->autoflush;
# remove prev progress
print "\b" x length($progressString) if defined $progressString;
# do lots of processing, update $counter
$progressString = "Thread #$tid. $x / $length1"; # No more newline
print $progressString; # Will print, because auto-flush is on
}
2.
类似
my $progress = Term::ProgressBar->new($length1);
$progress->update($x);
提前谢谢你。
我的脚本的工作变体如下:
use Win32::Console::ANSI; # for Windows and nothing for linux
# ...
#---OUTPUT----------------------
if ( !($x % 10) ) {
local $| = 1;
# Choose the line for thread ($i - thread_id)
print "\n" x $i;
# Remove prev. progress
print "\b" x length($progressString) if defined $progressString;
# Do lots of processing, update
$progressString = " Thread #$i. $x / $length1";
print $progressString; # Will print, because auto-flush is on
print "\e[A" x $i, "\r"; # Back to begin before printing
}
#-------------------------------
我的所有线程都想将它们的进度打印到同一行终端。我不能让他们选择不同的线路。我该如何处理? (linux & windows,如果可能的话)
编辑:
我尝试了两种变体:
1.
当我打印 '\n' 时,行下降,\b 不删除 \n 字符:
if ( !($x % 10) )
{
local $| = 1; # Or use IO::Handle; STDOUT->autoflush;
# remove prev progress
print "\b" x length($progressString) if defined $progressString;
# do lots of processing, update $counter
$progressString = "Thread #$tid. $x / $length1"; # No more newline
print $progressString; # Will print, because auto-flush is on
}
2.
类似
my $progress = Term::ProgressBar->new($length1);
$progress->update($x);
提前谢谢你。
我的脚本的工作变体如下:
use Win32::Console::ANSI; # for Windows and nothing for linux
# ...
#---OUTPUT----------------------
if ( !($x % 10) ) {
local $| = 1;
# Choose the line for thread ($i - thread_id)
print "\n" x $i;
# Remove prev. progress
print "\b" x length($progressString) if defined $progressString;
# Do lots of processing, update
$progressString = " Thread #$i. $x / $length1";
print $progressString; # Will print, because auto-flush is on
print "\e[A" x $i, "\r"; # Back to begin before printing
}
#-------------------------------