public class ProgressManager extends Object implements AutoCloseable
try (ProgressManager progress = new ProgressManager(term, Progress.Spinner.CLOCK)) {
Future<String> first = progress.addTask("First Task", 10000, task -> {
// All the work
task.accept(10000);
return "OK";
});
Future<String> second = progress.addTask("Second Task", 10000, task -> {
// All the work
task.accept(10000);
return "OK";
});
progress.waitAbortable();
term.println("First: " + first.get());
term.println("Second: " + second.get());
} finally {
term.println();
}
| Modifier and Type | Class and Description |
|---|---|
static interface |
ProgressManager.ProgressAsyncHandler<T> |
static interface |
ProgressManager.ProgressHandler<T> |
| Constructor and Description |
|---|
ProgressManager(Terminal terminal,
Progress.Spinner spinner)
Create a progress bar using the given terminal.
|
ProgressManager(Terminal terminal,
Progress.Spinner spinner,
int max_tasks)
Create a progress bar using the given terminal.
|
| Modifier and Type | Method and Description |
|---|---|
<T> Future<T> |
addTask(String title,
long total,
ProgressManager.ProgressAsyncHandler<T> handler)
Add a task to be done while showing progress.
|
<T> Future<T> |
addTask(String title,
long total,
ProgressManager.ProgressHandler<T> handler)
Add a task to be done while showing progress.
|
void |
close()
Close the progress and all tasks associated with it.
|
protected List<String> |
lines() |
void |
waitAbortable()
Wait for all scheduled tasks to finish allowing the user to abort all
tasks with <ctrl>-C.
|
public ProgressManager(@Nonnull Terminal terminal, @Nonnull Progress.Spinner spinner)
terminal - The terminal to use.spinner - The spinner to use.public ProgressManager(@Nonnull Terminal terminal, @Nonnull Progress.Spinner spinner, int max_tasks)
terminal - The terminal to use.spinner - The spinner to use.max_tasks - Maximum number fo concurrent inProgress.public void close()
close in interface AutoCloseablepublic void waitAbortable()
throws IOException,
InterruptedException
IOException - If interrupted by user.InterruptedException - If interrupted by system or other threads.public <T> Future<T> addTask(String title, long total, ProgressManager.ProgressAsyncHandler<T> handler)
T - The return type for the task.title - The progress title of the task.total - The total progress to complete.handler - The handler to do the task behind the progress being shown.public <T> Future<T> addTask(String title, long total, ProgressManager.ProgressHandler<T> handler)
T - The return type for the task.title - The progress title of the task.total - The total progress to complete.handler - The handler to do the task behind the progress being shown.Copyright © 2017. All rights reserved.