mabe02 / lanterna

Java library for creating text-based GUIs
GNU Lesser General Public License v3.0
2.23k stars 243 forks source link

progressbar not showing/updating #574

Closed damnms closed 1 year ago

damnms commented 1 year ago

i have a downloader application that uses right now the regular terminal (system.out.println, yeah). that application has a listener that fires every second and tells me how much it transferred. i would like to use lanterna to show a progressbar instead that system.out.println, but i am failing. the progressbar is shown once (when i debug), and then only a blue screen, no updates etc. but when i debug, i see that the progressbar has the correct values and also the window looks ok

i assume its a threading problem, but no idea ...

that method i have is:

    @Override
    public void transfered(Dto dto, String remoteFilename, long bytes, long size) {
        if (!downloadProgress.containsKey(remoteFilename)) {
            downloadProgress.put(remoteFilename, bytes);
        } else {
            Long aLong = downloadProgress.get(remoteFilename);
            long transferred = aLong + bytes;
            downloadProgress.put(remoteFilename, transferred);
        }
        long percent = downloadProgress.get(remoteFilename) * 100 / size;
        System.out.println("\rTransfered " + percent + "% for " + remoteFilename);
        progressBar.setValue((int) percent);

    }

my text is shown in a terminal, that is correct. but somehow, progressbar is not updated :/ in the constructor i use:

    final ProgressBar progressBar = new ProgressBar(0, 100, 10);
    final BasicWindow transferWindow = new BasicWindow("Downloading...");
        transferWindow.setComponent(progressBar);

and just before the download starts i set the window once with: textGUI.addWindow(transferWindow);

any idea?

damnms commented 1 year ago

had to add textGUI.updateScreen(); - now it works