Class ProgressLine

  • All Implemented Interfaces:
    AutoCloseable, Flow.Subscriber<Progress>

    public class ProgressLine
    extends Object
    implements Flow.Subscriber<Progress>, AutoCloseable
    Show progress on a single task in how many percent (with spinner and progress-bar). Spinner type is configurable. This is the single-thread progress where everything is handled in the same thread as calls onNext(Progress). This class is not thread safe.

    Example usage:

    
     try (val progress = new ProgressLine(DefaultSpinners.ASCII, "Do Thing")) {
         for (int i = 0; i < 100; ++i) {
             // Do some action that is needed 100 times here.
             progress.onNext(new Progress(i, 100));
         }
         progress.onComplete();
     }
     
    • Constructor Detail

      • ProgressLine

        public ProgressLine​(Spinner spinner,
                            String title)
        Create a progress bar using the default terminal.
        Parameters:
        spinner - The spinner to use.
        title - The title of the progress.
      • ProgressLine

        public ProgressLine​(net.morimekta.io.tty.TTY tty,
                            Spinner spinner,
                            String title)
        Create a progress bar using the default terminal.
        Parameters:
        tty - TTY instance.
        spinner - The spinner to use.
        title - The title of the progress.
      • ProgressLine

        public ProgressLine​(PrintStream out,
                            IntSupplier widthSupplier,
                            Spinner spinner,
                            String title)
        Create a progress bar using the line printer and width supplier.
        Parameters:
        out - The line printer used to update visible progress.
        widthSupplier - The width supplier to get terminal width from.
        spinner - The spinner to use.
        title - The title of the progress.
      • ProgressLine

        protected ProgressLine​(PrintStream out,
                               IntSupplier widthSupplier,
                               Clock clock,
                               Spinner spinner,
                               String title)
        Create a progress updater. Note that either terminal or the updater param must be set.
        Parameters:
        out - The terminal to print to.
        widthSupplier - The width sclock.millis()upplier to get terminal width from.
        clock - The clock to use for timing.
        spinner - The spinner type.
        title - What progresses.