@@ -37,8 +37,20 @@ use My::Platform;
3737use POSIX qw[ _exit ] ;
3838use IO::Handle qw[ flush ] ;
3939use mtr_results;
40-
4140use Term::ANSIColor;
41+ use English;
42+
43+ my $tot_real_time = 0;
44+ my $tests_done = 0;
45+ my $tests_failed = 0;
46+
47+ our $timestamp = 0;
48+ our $timediff = 0;
49+ our $name ;
50+ our $verbose ;
51+ our $verbose_restart = 0;
52+ our $timer = 1;
53+ our $tests_total ;
4254
4355my %color_map = qw/ pass green
4456 retry-pass green
@@ -47,20 +59,39 @@ my %color_map = qw/pass green
4759 disabled bright_black
4860 skipped yellow
4961 reset reset/ ;
50- sub xterm_color {
51- if (-t STDOUT and defined $ENV {TERM } and $ENV {TERM } =~ / xterm/ ) {
52- syswrite STDOUT , color($color_map {$_ [0]});
62+
63+ my $set_titlebar ;
64+ my $set_color = sub { };
65+
66+ if (-t STDOUT ) {
67+ if (IS_WINDOWS) {
68+ eval {
69+ require Win32::Console;
70+ $set_titlebar = sub { &Win32::Console::Title($_ [0]);};
71+ }
72+ } elsif ($ENV {TERM } =~ / xterm/ ) {
73+ $set_titlebar = sub { syswrite STDOUT , " \e ]0;$_ [0]\a " ; };
74+ $set_color = sub { syswrite STDOUT , color($color_map {$_ [0]}); }
5375 }
5476}
5577
56- my $tot_real_time = 0;
78+ sub titlebar_stat ($) {
5779
58- our $timestamp = 0;
59- our $timediff = 0;
60- our $name ;
61- our $verbose ;
62- our $verbose_restart = 0;
63- our $timer = 1;
80+ sub time_format ($) {
81+ sprintf ' %d:%02d:%02d' , $_ [0]/3600, ($_ [0]/60)%60, $_ [0]%60;
82+ }
83+
84+ $tests_done ++;
85+ $tests_failed ++ if $_ [0] =~ / fail/ ;
86+ $tests_total ++ if $_ [0] =~ / retry/ ;
87+
88+ my $spent = time - $BASETIME ;
89+ my $left = $tests_total - $tests_done ;
90+
91+ &$set_titlebar (sprintf " mtr: spent %s on %d tests. %s (%d tests) left, %d failed" ,
92+ time_format($spent ), $tests_done ,
93+ time_format($spent /$tests_done * $left ), $left , $tests_failed );
94+ }
6495
6596sub report_option {
6697 my ($opt , $value )= @_ ;
@@ -321,8 +352,6 @@ sub mtr_report_stats ($$$$) {
321352
322353 if ( $timer )
323354 {
324- use English;
325-
326355 mtr_report(" Spent" , sprintf (" %.3f" , $tot_real_time )," of" ,
327356 time - $BASETIME , " seconds executing testcases" );
328357 }
@@ -620,10 +649,11 @@ sub mtr_report (@) {
620649 my @s = split /\[ (\S+) \]/, _name() . " @_ \n " ;
621650 if (@s > 1) {
622651 print $s [0];
623- xterm_color ($s [1]);
652+ & $set_color ($s [1]);
624653 print " [ $s [1] ]" ;
625- xterm_color (' reset' );
654+ & $set_color (' reset' );
626655 print $s [2];
656+ titlebar_stat($s [1]) if $set_titlebar ;
627657 } else {
628658 print $s [0];
629659 }
0 commit comments