presto-cli/src/main/java/io/prestosql/cli/FormatUtils.java/FormatUtils/formatProgressBar
class FormatUtils:    public static String formatProgressBar(int width, int complete, int running, int total)
    {
        if (total == 0) {
            return repeat(" ", width);
        }

        int pending = max(0, total - complete - running);

        // compute nominal lengths
        int completeLength = min(width, ceil(complete * width, total));
        int pendingLength = min(width, ceil(pending * width, total));

        // leave space for at least one ">" as long as running is > 0
        int minRunningLength = (running > 0) ? 1 : 0;
        int runningLength = max(min(width, ceil(running * width, total)), minRunningLength);

        // adjust to fix rounding errors
        if (((completeLength + runningLength + pendingLength) != width) && (pending > 0)) {
            // sacrifice "pending" if we're over the max width
            pendingLength = max(0, width - completeLength - runningLength);
        }
        if ((completeLength + runningLength + pendingLength) != width) {
            // then, sacrifice "running"
            runningLength = max(minRunningLength, width - completeLength - pendingLength);
        }
        if (((completeLength + runningLength + pendingLength) > width) && (complete > 0)) {
            // finally, sacrifice "complete" if we're still over the limit
            completeLength = max(0, width - runningLength - pendingLength);
        }

        checkState((completeLength + runningLength + pendingLength) == width,
                "Expected completeLength (%s) + runningLength (%s) + pendingLength (%s) == width (%s), was %s for complete = %s, running = %s, total = %s",
                completeLength, runningLength, pendingLength, width, completeLength + runningLength + pendingLength, complete, running, total);

        return repeat("=", completeLength) + repeat(">", runningLength) + repeat(" ", pendingLength);
    }