Skip to content

Commit 7021a3c

Browse files
committed
[+] PBar: Fluent config
1 parent d6fb038 commit 7021a3c

File tree

1 file changed

+41
-11
lines changed

1 file changed

+41
-11
lines changed

src/main/java/org/hydev/mcpm/client/interaction/ProgressRow.java

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package org.hydev.mcpm.client.interaction;
22

3-
import java.util.Objects;
4-
53
import static java.lang.String.format;
64

75
/**
@@ -14,26 +12,33 @@ public class ProgressRow
1412
{
1513
private final long total;
1614
private long completed;
17-
private final String unit;
18-
19-
private long startTime;
15+
private String unit;
2016
private ProgressBar pb;
17+
private String desc;
18+
private int descLen;
19+
private String fmt;
20+
21+
private final long startTime;
2122

22-
public ProgressRow(long total, String unit)
23+
public ProgressRow(long total)
2324
{
2425
this.total = total;
2526
this.completed = 0;
26-
27-
// Add leading space
28-
this.unit = (!unit.isBlank() && !unit.startsWith(" ")) ? " " + unit : unit;
27+
this.unit = " it";
28+
this.desc = "";
29+
this.descLen = 20;
30+
this.fmt = "{desc}{speed} {eta} {prefix}{progbar}{suffix} {%done}";
2931

3032
// Record start time for speed estimation
3133
this.startTime = System.nanoTime();
3234
}
3335

34-
public ProgressRow(long total)
36+
/**
37+
* @return Elapsed time in seconds
38+
*/
39+
private double elapsed()
3540
{
36-
this(total, "it");
41+
return (System.nanoTime() - startTime) / 1e9d;
3742
}
3843

3944
/**
@@ -87,4 +92,29 @@ public void set(long completed)
8792
pb.update();
8893
if (completed >= total) pb.finishBar(this);
8994
}
95+
96+
public ProgressRow desc(String desc)
97+
{
98+
this.desc = desc;
99+
return this;
100+
}
101+
102+
public ProgressRow descLen(int descLen)
103+
{
104+
this.descLen = descLen;
105+
return this;
106+
}
107+
108+
public ProgressRow unit(String unit)
109+
{
110+
// Add leading space
111+
this.unit = (!unit.isBlank() && !unit.startsWith(" ")) ? " " + unit : unit;
112+
return this;
113+
}
114+
115+
public ProgressRow fmt(String fmt)
116+
{
117+
this.fmt = fmt;
118+
return this;
119+
}
90120
}

0 commit comments

Comments
 (0)