Skip to content

Commit 3c4f992

Browse files
committed
Add --progress flag
1 parent 370a501 commit 3c4f992

File tree

1 file changed

+32
-10
lines changed

1 file changed

+32
-10
lines changed

src/main/java/com/glencoesoftware/bioformats2raw/Converter.java

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,13 @@ public class Converter implements Callable<Void> {
157157
)
158158
private volatile String logLevel = "WARN";
159159

160+
@Option(
161+
names = {"-p", "--progress"},
162+
description = "Print progress bars during conversion",
163+
help = true
164+
)
165+
private volatile boolean progressBars = false;
166+
160167
@Option(
161168
names = "--version",
162169
description = "Print version information and exit",
@@ -1021,18 +1028,26 @@ public void saveResolutions(int series)
10211028
List<CompletableFuture<Void>> futures =
10221029
new ArrayList<CompletableFuture<Void>>();
10231030

1024-
ProgressBarBuilder builder = new ProgressBarBuilder()
1025-
.setInitialMax(tileCount)
1026-
.setTaskName(String.format("[%d/%d]", series, resolution));
1031+
final ProgressBar pb;
1032+
if (progressBars) {
1033+
ProgressBarBuilder builder = new ProgressBarBuilder()
1034+
.setInitialMax(tileCount)
1035+
.setTaskName(String.format("[%d/%d]", series, resolution));
1036+
1037+
if (!(logLevel.equals("OFF") ||
1038+
logLevel.equals("ERROR") ||
1039+
logLevel.equals("WARN")))
1040+
{
1041+
builder.setConsumer(new DelegatingProgressBarConsumer(LOGGER::trace));
1042+
}
10271043

1028-
if (!(logLevel.equals("OFF") ||
1029-
logLevel.equals("ERROR") ||
1030-
logLevel.equals("WARN")))
1031-
{
1032-
builder.setConsumer(new DelegatingProgressBarConsumer(LOGGER::trace));
1044+
pb = builder.build();
1045+
}
1046+
else {
1047+
pb = null;
10331048
}
10341049

1035-
try (ProgressBar pb = builder.build()) {
1050+
try {
10361051
for (int j=0; j<scaledHeight; j+=tileHeight) {
10371052
final int yy = j;
10381053
int height = (int) Math.min(tileHeight, scaledHeight - yy);
@@ -1061,7 +1076,9 @@ public void saveResolutions(int series)
10611076
resolution, plane, xx, yy, width, height, t);
10621077
}
10631078
finally {
1064-
pb.step();
1079+
if (pb != null) {
1080+
pb.step();
1081+
}
10651082
}
10661083
});
10671084
}
@@ -1077,6 +1094,11 @@ public void saveResolutions(int series)
10771094
// and need re-throwing
10781095

10791096
}
1097+
finally {
1098+
if (pb != null) {
1099+
pb.close();
1100+
}
1101+
}
10801102
}
10811103
}
10821104

0 commit comments

Comments
 (0)