@@ -48,20 +48,30 @@ private double elapsed()
48
48
* @param cols Number of columns (width) of the terminal window
49
49
* @return Formatted string
50
50
*/
51
- public String fmt (ProgressBarTheme theme , int cols )
51
+ public String toString (ProgressBarTheme theme , int cols )
52
52
{
53
- double p = 100d * completed / total ;
54
- var placeholder = "PLACEHOLDER_BAR" ;
55
- var t = format ("%s%s%s %3.0f%% %5d/%-5d%s" , theme .prefix (), placeholder , theme .suffix (), p , completed , total , unit );
53
+ // Calculate speed. TODO: Use a moving window to calculate speed
54
+ double speed = completed / elapsed ();
55
+ double eta = total / speed ;
56
+ long eta_s = (long ) (eta % 60 ), eta_m = (long ) (eta / 60 );
57
+
58
+ // Replace variables
59
+ var p = format ("%3.0f%%" , 100d * completed / total );
60
+ var t = fmt .replace ("{prefix}" , theme .prefix ())
61
+ .replace ("{suffix}" , theme .suffix ())
62
+ .replace ("{%done}" , p )
63
+ .replace ("{eta}" , format ("%02d:%02d" , eta_m , eta_s ))
64
+ .replace ("{speed}" , format ("%.2f%s/s" , speed , unit ))
65
+ .replace ("{desc}" , descLen != 0 ? format ("%-" + descLen + "s" , desc ) : desc + " " );
56
66
57
67
// Add progress bar length
58
- var len = cols - t .length () + placeholder .length ();
68
+ var len = cols - t .length () + "{progbar}" .length ();
59
69
60
70
// Calculate progress length
61
71
int pLen = (int ) (1d * completed / total * len );
62
72
var bar = theme .done ().repeat (pLen / theme .doneLen ()) + theme .ipr ().repeat ((len - pLen ) / theme .iprLen ());
63
73
64
- return t .replaceFirst ( placeholder , bar );
74
+ return t .replace ( "{progbar}" , bar );
65
75
}
66
76
67
77
public void setPb (ProgressBar pb )
0 commit comments