- java.lang.Object
-
- net.morimekta.terminal.progress.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 callsonNext(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 Summary
Constructors Modifier Constructor Description protected
ProgressLine(PrintStream out, IntSupplier widthSupplier, Clock clock, Spinner spinner, String title)
Create a progress updater.ProgressLine(PrintStream out, IntSupplier widthSupplier, Spinner spinner, String title)
Create a progress bar using the line printer and width supplier.ProgressLine(net.morimekta.io.tty.TTY tty, Spinner spinner, String title)
Create a progress bar using the default terminal.ProgressLine(Spinner spinner, String title)
Create a progress bar using the default terminal.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
boolean
isDone()
void
onComplete()
void
onError(Throwable throwable)
void
onNext(Progress current)
Update the progress to reflect the current progress value.void
onSubscribe(Flow.Subscription subscription)
-
-
-
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.
-
-
Method Detail
-
onSubscribe
public void onSubscribe(Flow.Subscription subscription)
- Specified by:
onSubscribe
in interfaceFlow.Subscriber<Progress>
-
onNext
public void onNext(Progress current)
Update the progress to reflect the current progress value.- Specified by:
onNext
in interfaceFlow.Subscriber<Progress>
- Parameters:
current
- The new current progress value.
-
onComplete
public void onComplete()
- Specified by:
onComplete
in interfaceFlow.Subscriber<Progress>
-
onError
public void onError(Throwable throwable)
- Specified by:
onError
in interfaceFlow.Subscriber<Progress>
-
close
public void close()
- Specified by:
close
in interfaceAutoCloseable
-
isDone
public boolean isDone()
- Returns:
- If the progress task is done.
-
-