// Path: src/main/java/me/tongfei/progressbar/Util.java
// static ConsoleProgressBarConsumer createConsoleConsumer(int predefinedWidth) {
//     PrintStream real = new PrintStream(new FileOutputStream(FileDescriptor.err));
//     return createConsoleConsumer(real, predefinedWidth);  // System.err might be overridden by System.setErr
// }


import me.tongfei.progressbar.wrapped.*;
import static me.tongfei.progressbar.Util.createConsoleConsumer;
import java.io.*;
import java.text.DecimalFormat;
import java.time.Duration;
import java.time.temporal.ChronoUnit;
import java.util.Arrays;
import java.util.Iterator;
import java.util.Spliterator;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.stream.BaseStream;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
package me.tongfei.progressbar;




/**
 * A console-based progress bar with minimal runtime overhead.
 * @author Tongfei Chen
 */
public class ProgressBar implements AutoCloseable {

    private ProgressState progress;
    private ProgressUpdateAction action;
    private ScheduledFuture<?> scheduledTask;

    /**
     * Creates a progress bar with the specific taskName name and initial maximum value.
     * @param task Task name
     * @param initialMax Initial maximum value
     */
    public ProgressBar(String task, long initialMax) {
        this(task, initialMax, 1000, false, System.err, ProgressBarStyle.COLORFUL_UNICODE_BLOCK, "", 1, false, null, ChronoUnit.SECONDS, 0L, Duration.ZERO);
    }

    /**
     * Creates a progress bar with the specific taskName name, initial maximum value,
     * customized update interval (default 1000 ms), the PrintStream to be used, and output style.
     * @param task Task name
     * @param initialMax Initial maximum value
     * @param updateIntervalMillis Update interval (default value 1000 ms)
     * @param continuousUpdate Rerender every time the update interval happens regardless of progress count.
     * @param style Output style (default value ProgressBarStyle.UNICODE_BLOCK)
     * @param showSpeed Should the calculated speed be displayed
     * @param speedFormat Speed number format
     * @deprecated Use {@link ProgressBarBuilder} instead.
     */
    public ProgressBar(
            String task,
            long initialMax,
            int updateIntervalMillis,
            boolean continuousUpdate,
            PrintStream os,
            ProgressBarStyle style,
            String unitName,
            long unitSize,
            boolean showSpeed,
            DecimalFormat speedFormat,
            ChronoUnit speedUnit,
            long processed,
            Duration elapsed
    ) {
        this(task, initialMax, updateIntervalMillis, continuousUpdate, processed, elapsed,
                new DefaultProgressBarRenderer(style, unitName, unitSize, showSpeed, speedFormat, speedUnit),
// Path: src/main/java/me/tongfei/progressbar/Util.java
// static ConsoleProgressBarConsumer createConsoleConsumer(int predefinedWidth) {
//     PrintStream real = new PrintStream(new FileOutputStream(FileDescriptor.err));
//     return createConsoleConsumer(real, predefinedWidth);  // System.err might be overridden by System.setErr
// }


// Path: src/main/java/me/tongfei/progressbar/ProgressBar.java
import me.tongfei.progressbar.wrapped.*;
import static me.tongfei.progressbar.Util.createConsoleConsumer;
import java.io.*;
import java.text.DecimalFormat;
import java.time.Duration;
import java.time.temporal.ChronoUnit;
import java.util.Arrays;
import java.util.Iterator;
import java.util.Spliterator;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.stream.BaseStream;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;

package me.tongfei.progressbar;




/**
 * A console-based progress bar with minimal runtime overhead.
 * @author Tongfei Chen
 */
public class ProgressBar implements AutoCloseable {

    private ProgressState progress;
    private ProgressUpdateAction action;
    private ScheduledFuture<?> scheduledTask;

    /**
     * Creates a progress bar with the specific taskName name and initial maximum value.
     * @param task Task name
     * @param initialMax Initial maximum value
     */
    public ProgressBar(String task, long initialMax) {
        this(task, initialMax, 1000, false, System.err, ProgressBarStyle.COLORFUL_UNICODE_BLOCK, "", 1, false, null, ChronoUnit.SECONDS, 0L, Duration.ZERO);
    }

    /**
     * Creates a progress bar with the specific taskName name, initial maximum value,
     * customized update interval (default 1000 ms), the PrintStream to be used, and output style.
     * @param task Task name
     * @param initialMax Initial maximum value
     * @param updateIntervalMillis Update interval (default value 1000 ms)
     * @param continuousUpdate Rerender every time the update interval happens regardless of progress count.
     * @param style Output style (default value ProgressBarStyle.UNICODE_BLOCK)
     * @param showSpeed Should the calculated speed be displayed
     * @param speedFormat Speed number format
     * @deprecated Use {@link ProgressBarBuilder} instead.
     */
    public ProgressBar(
            String task,
            long initialMax,
            int updateIntervalMillis,
            boolean continuousUpdate,
            PrintStream os,
            ProgressBarStyle style,
            String unitName,
            long unitSize,
            boolean showSpeed,
            DecimalFormat speedFormat,
            ChronoUnit speedUnit,
            long processed,
            Duration elapsed
    ) {
        this(task, initialMax, updateIntervalMillis, continuousUpdate, processed, elapsed,
                new DefaultProgressBarRenderer(style, unitName, unitSize, showSpeed, speedFormat, speedUnit),
                createConsoleConsumer(os)