Add the carrot to progress bar

This commit is contained in:
Zontreck 2024-02-11 17:12:53 -07:00
parent 8fc4a58b6f
commit 3d50d8f4ec

View file

@ -10,6 +10,11 @@ public class ProgressBar
private static final int DEFAULT_BAR_WIDTH = 50; private static final int DEFAULT_BAR_WIDTH = 50;
/**
* Reserved spaces for the brackets, and the carrot, and the percent value.
*/
private static final int PROGRESS_BAR_RESERVED=5;
/** /**
* Always will return 80 * Always will return 80
* @return 80 * @return 80
@ -30,7 +35,7 @@ public class ProgressBar
public static String printProgressBar(int percent, String beforeText, String afterText) { public static String printProgressBar(int percent, String beforeText, String afterText) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
int consoleWidth = getConsoleWidth(); int consoleWidth = getConsoleWidth();
int barWidth = Math.min(consoleWidth - beforeText.length() - afterText.length() - 4, DEFAULT_BAR_WIDTH); int barWidth = Math.min(consoleWidth - beforeText.length() - afterText.length() - PROGRESS_BAR_RESERVED, DEFAULT_BAR_WIDTH);
// Calculate progress // Calculate progress
int progressBarLength = (int) ((double) percent / 100 * barWidth); int progressBarLength = (int) ((double) percent / 100 * barWidth);