Package net.morimekta.console.terminal
Class Progress
- java.lang.Object
-
- net.morimekta.console.terminal.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 callsaccept(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.
-
-
-
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 interfacejava.util.function.LongConsumer
- Parameters:
current
- The new current progress value.
-
close
public void close()
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfaceProgressTask
-
isDone
public boolean isDone()
Description copied from interface:ProgressTask
If the progress task is done or aborted.- Specified by:
isDone
in interfaceProgressTask
- Returns:
- True if done.
-
-