Skip to content

Commit ccc8365

Browse files
committed
[F] PBar: Fix progress row formatting logic
1 parent d96324c commit ccc8365

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@
1212
* @since 2022-09-27
1313
*/
1414
public record ProgressBarTheme(
15-
String ipr,
1615
String done,
17-
int iprLen,
18-
int doneLen
16+
String ipr,
17+
String prefix,
18+
String suffix,
19+
int doneLen,
20+
int iprLen
1921
)
2022
{
21-
public static final ProgressBarTheme ASCII_THEME = new ProgressBarTheme("#", "-", 1, 1);
22-
public static final ProgressBarTheme CLASSIC_THEME = new ProgressBarTheme("█", ".", 1, 1);
23-
public static final ProgressBarTheme EMOJI_THEME = new ProgressBarTheme("✅", "🕑", 2, 2);
24-
public static final ProgressBarTheme FLOWER_THEME = new ProgressBarTheme("🌸", "🥀", 2, 2);
23+
public static final ProgressBarTheme ASCII_THEME = new ProgressBarTheme("#", "-", "[", "]", 1, 1);
24+
public static final ProgressBarTheme CLASSIC_THEME = new ProgressBarTheme("█", ".", "", "", 1, 1);
25+
public static final ProgressBarTheme EMOJI_THEME = new ProgressBarTheme("✅", "🕑", "", "", 2, 2);
26+
public static final ProgressBarTheme FLOWER_THEME = new ProgressBarTheme("🌸", "🥀", "", "", 2, 2);
2527
}

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,21 @@ public ProgressRow(long total)
3030
* Get formatted string of the current progress bar
3131
*
3232
* @param theme Progress bar theme
33+
* @param cols Number of columns (width) of the terminal window
3334
* @return Formatted string
3435
*/
35-
public String fmt(ProgressBarTheme theme)
36+
public String fmt(ProgressBarTheme theme, int cols)
3637
{
3738
double p = 100d * completed / total;
3839
var placeholder = "PLACEHOLDER_BAR";
3940
var t = format("%s%s%s %.0f %d/%d%s", theme.prefix(), placeholder, theme.suffix(), p, completed, total, unit);
4041

4142
// Add progress bar length
42-
var len = t.length() - placeholder.length();
43+
var len = cols - t.length() + placeholder.length();
4344

4445
// Calculate progress length
45-
int pLen = (int) (completed / total * len);
46-
var bar = theme.done().repeat(pLen / theme.doneLen()) + theme.ipr().repeat(pLen / theme.iprLen());
46+
int pLen = (int) (1d * completed / total * len);
47+
var bar = theme.done().repeat(pLen / theme.doneLen()) + theme.ipr().repeat((len - pLen) / theme.iprLen());
4748

4849
return t.replaceFirst(placeholder, bar);
4950
}

0 commit comments

Comments
 (0)