Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Progressbar doesn't print in single line #82

Closed
cloudnotify opened this issue Jul 16, 2020 · 6 comments
Closed

Progressbar doesn't print in single line #82

cloudnotify opened this issue Jul 16, 2020 · 6 comments

Comments

@cloudnotify
Copy link

cloudnotify commented Jul 16, 2020

Kudos for the great utility @ctongfei , I had integrated progress bar with my application and the progress keep printing in new line(Tried in terminal and eclipse ).I'm using apache log4j2 for logging. Below is my code.

`

                try (InputStream inputStream = new FileInputStream(source);
	    		ProgressBar pb = new ProgressBarBuilder()
	            .setInitialMax(inputStream.available())
	            .setTaskName("Transfering")
	            .setConsumer(new DelegatingProgressBarConsumer(logger
                ::info)).setUnit("MB", 1048576)
	            .build()) {
		    

                byte[] chunk = new byte[102400];
		    int chunkLen = 0;
		    

		    while ((chunkLen = inputStream.read(chunk)) != -1) {
		    	pb.stepBy(chunkLen);
		    	session.getBasicRemote().sendBinary(ByteBuffer.wrap(chunk, 0, chunkLen));
		    }
		  
	     
	        } catch (IOException ex) {
	        	
	            logger.log(Level.ERROR,"Error ouccured while sending data from client ::",ex);
	        }`

Also i have tried all the visual styles. Any help is appreciated.

test

@ctongfei
Copy link
Owner

Maybe we should reopen this as this seems to be a valid concern?
It seems that it is because the header of the logger each line. Probably would be fixed if #71 is fixed, so that you can set a custom width?

@cloudnotify cloudnotify reopened this Jul 17, 2020
@cloudnotify
Copy link
Author

cloudnotify commented Jul 17, 2020

Thanks a lot @ctongfei, but i'm wondering how #71 is relevant to this. Here, the issue is with progress-bar interaction with logger. :-)

@ctongfei
Copy link
Owner

@cloudnotify The progress bar has no knowledge of your logger header [16 Jul 2020 22:59:57 INFO ] - , so the computed width is wrong

@cloudnotify
Copy link
Author

Thanks for the explanation @ctongfei

@tahifaMed
Copy link

Is there any Solution For this issue , I need some help, thank you

@ctongfei
Copy link
Owner

Fixed in 0.9.0. You might want to do

new DelegatingProgressBarConsumer(logger::info, <MAX WIDTH>)

where <MAX WIDTH> is the length of your terminal minus the length of your logger prefix (e.g. [16 Jul 2020 22:59:57 INFO ] - ).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants