Class Progress

  • All Implemented Interfaces:
    java.lang.AutoCloseable, java.util.function.LongConsumer, ProgressTask

    public class Progress
    extends java.lang.Object
    implements ProgressTask
    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 accept(long). This class is not thread safe.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Progress.Spinner
      Which spinner to show.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
        Progress​(LinePrinter updater, java.util.function.IntSupplier widthSupplier, Progress.Spinner spinner, java.lang.String title, long total)
      Create a progress bar using the line printer and width supplier.
      protected Progress​(Terminal terminal, LinePrinter updater, java.util.function.IntSupplier widthSupplier, java.time.Clock clock, Progress.Spinner spinner, java.lang.String title, long total)
      Create a progress updater.
        Progress​(Terminal terminal, Progress.Spinner spinner, java.lang.String title, long total)
      Create a progress bar using the given terminal.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void accept​(long current)
      Update the progress to reflect the current progress value.
      void close()  
      boolean isDone()
      If the progress task is done or aborted.
      • Methods inherited from interface java.util.function.LongConsumer

        andThen
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Progress

        public Progress​(@Nonnull
                        Terminal terminal,
                        @Nonnull
                        Progress.Spinner spinner,
                        @Nonnull
                        java.lang.String title,
                        long total)
        Create a progress bar using the given terminal.
        Parameters:
        terminal - The terminal to use.
        spinner - The spinner to use.
        title - The title of the progress.
        total - The total progress value.
      • Progress

        public Progress​(@Nonnull
                        LinePrinter updater,
                        @Nonnull
                        java.util.function.IntSupplier widthSupplier,
                        @Nonnull
                        Progress.Spinner spinner,
                        @Nonnull
                        java.lang.String title,
                        long total)
        Create a progress bar using the line printer and width supplier.
        Parameters:
        updater - 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.
        total - The total progress value.
      • Progress

        protected Progress​(@Nullable
                           Terminal terminal,
                           @Nullable
                           LinePrinter updater,
                           @Nonnull
                           java.util.function.IntSupplier widthSupplier,
                           @Nonnull
                           java.time.Clock clock,
                           @Nonnull
                           Progress.Spinner spinner,
                           @Nonnull
                           java.lang.String title,
                           long total)
        Create a progress updater. Note that either terminal or the updater param must be set.
        Parameters:
        terminal - The terminal to print to.
        updater - The updater to write to.
        widthSupplier - The width supplier to get terminal width from.
        clock - The clock to use for timing.
        spinner - The spinner type.
        title - What progresses.
        total - The total value to be 'progressed'.
    • Method Detail

      • accept

        public void accept​(long current)
        Update the progress to reflect the current progress value.
        Specified by:
        accept in interface java.util.function.LongConsumer
        Parameters:
        current - The new current progress value.
      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface ProgressTask
      • isDone

        public boolean isDone()
        Description copied from interface: ProgressTask
        If the progress task is done or aborted.
        Specified by:
        isDone in interface ProgressTask
        Returns:
        True if done.