commit 4f2c871d004e2598e7f6c29c10a5de6bb273a4a8
parent 04750e2c55e7f2df7d9cef87f94030137a8856cb
Author: Matthias Jaros <jaros@mailbox.org>
Date: Mon, 16 Feb 2026 17:38:33 +0100
Fixed bug that cursors moves too much up and deletes lines depending on
number of target hosts
Diffstat:
1 file changed, 15 insertions(+), 10 deletions(-)
diff --git a/src/main/java/com/it_jaros/networkScanner/ProgressBar.java b/src/main/java/com/it_jaros/networkScanner/ProgressBar.java
@@ -11,23 +11,24 @@ public class ProgressBar {
public void start(List<Progress> hosts) {
final int lines = hosts.size();
- System.out.print("\n\n");
+ hosts.forEach((h) -> System.out.print("\n"));
ui.scheduleAtFixedRate(() -> {
- // move cursor UP to where bars start
+ // clear bars by moving cursor up
System.out.print("\u001b[" + lines + "A");
-
+
+ // paint a bar per host
for (Progress progress : hosts) {
- System.out.print("\u001b[2K\r");
- System.out.println(bar(
- progress.host() + " open=" + progress.open().get(),
- progress.done().get(),
- progress.total()));
+ drawBar(progress);
}
}, 1, 200, TimeUnit.MILLISECONDS);
}
- public void stop() {
- ui.shutdown();
+ private void drawBar(Progress progress) {
+ System.out.print("\u001b[2K\r");
+ System.out.println(bar(
+ progress.host() + " open=" + progress.open().get(),
+ progress.done().get(),
+ progress.total()));
}
public String bar(String label, int done, int total) {
@@ -41,6 +42,10 @@ public class ProgressBar {
return String.format("%-25s %s %3d%% (%d/%d)", label, b, percent, done, total);
}
+ public void stop() {
+ ui.shutdown();
+ }
+
void onPortFinished(Progress p) {
p.done().incrementAndGet();
}