-
Notifications
You must be signed in to change notification settings - Fork 270
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
How to implement Multiple Progress Bars??? #31
Comments
Hi! Example package main
import (
"math/rand"
"pb"
"sync"
"time"
)
func main() {
pool := &pb.Pool{}
first := pb.New(1000).Prefix("First ")
second := pb.New(1000).Prefix("Second ")
third := pb.New(1000).Prefix("Third ")
pool.Add(first, second, third)
pool.Start()
wg := new(sync.WaitGroup)
for _, bar := range []*pb.ProgressBar{first, second, third} {
wg.Add(1)
go func(cb *pb.ProgressBar) {
for n := 0; n < 1000; n++ {
cb.Increment()
time.Sleep(time.Millisecond * time.Duration(rand.Intn(100)))
}
cb.Finish()
wg.Done()
}(bar)
}
wg.Wait()
} now have some problems, but i'm working on it |
Hi @cheggaaa... Thanks a lot for making this!!! The example works... Other suggestions to improve it:
This is a very valuable component! Let me know how I can help... I will work on integrating the example for multiple files uploads... Let me know when you integrate this! thanks! |
This commit adds the documentation for the README.md, along with the description of the result of running the example. * modified: README.md - Some refactoring - Adding the example * new file: example/multiple.go - Adding the example provided during the discusion of issue 31 - Adding the correct import statement for "pb"
Issue #31: Updating the Docs with Parallel Bars example
This not easy.. want to do this without heavy dependencies like ncurses. |
@cheggaaa That's alright! That's definitely a stretch... I will try to create an example for the Multiple IO downloads, which is what I need... I tried last night but I might have missed something... Thanks a lot for this!!! Easier than the others... |
Good news! Bad news - windows is not yet supported |
Needs to be done:
|
@cheggaaa I was able to implement the IO-based Progress Bars with the sample you have (this is a real app)... I can contribute with the code sample code based on https://github.com/thbar/golang-playground/blob/master/download-files.go. Wow, the locked input will definitely be great!!! :D I still have to test this on CI/CD environment (Travis and Jenkins for that matter)... Other than that, I'm glad my team is not on Windows :D sorry for the windows users... Hopefully someone will tackle that... In addition, I like your TODOs... I can't test neither on BSD nor Solaris (same situation)... Awesome! I'm so happy I got this working... I will work on the example code after tonight!!! |
Hi @cheggaaa... Here's a feedback with the use of the Terminal: It helps with blocking the console, but it creates TOO MANY scrolls!!! That was NOT the plan :( It is re-writing all the lines upon an update... I'd love to go back to square one, and be able to quit the process before... I had to close the window in order to stop the download of too many files and the experience was annoying... Anyway, this is just my 2cs... |
Not sure, I first thought that the commit 9ba607e worked... And I did not introduce any change to the library during my pull request... Your initial support worked as expected, where there's no buffer in the terminal nor the scroll grows over the updated values. However, I was tagging the commits, merging to my local fork, and the same scrolling behavior showed up again... Do you know why? The screenshot below shows the behavior of the terminal scrolling down instead of updating the status in-place, when compared to the first screenshot above. |
Reason for the problemif the number of PBs is greater than the number of lines in the current terminal window, then the scrolls will be engaged because of reprinting... Maximizing the terminal window to accommodate all my entries worked... Possible WorkaroundIf there's no way to solve this, Is there a way to get the total number of lines of the terminal? That way, the PB API could expose the dimensions of the terminal and enqueue only the maximum number of PBs to be running. Further, it would be a matter of enqueuing the remainder while PBs are finished... |
About ctrl+c. We need copy some code from this package https://github.com/golang/crypto/tree/master/ssh/terminal and write method 'lockInput' (like this https://github.com/golang/crypto/blob/master/ssh/terminal/util.go#L87 , but without reading from stdin). About many bars. I think user has no need more than 5-6 bars) and problems like queues should solve user. |
Can you check last version? Under linux signals works fine |
Well, the number of bars is up to the API Client to decide... What I'm suggesting is that if there are more bars than the terminal's current size can accommodate, then the PB API should give that information to the user's API... That way, users can use "Tickle" http://www.tecmint.com/manage-and-limit-downloadupload-bandwidth-with-trickle-in-linux/ to control the download bandwidth, or control the number of bars. I will verify the last version in a few hours... |
Any updates? |
So far it's alpha.. We have not windows support and have some problems with catching os signals |
Did you checked out go-keybind ? This library can catch user inputs and supports windows. |
As requested at cheggaaa/pb#31, this commit adds support to parallel progress bars that monitors the download of multiple files from Nexus. This is similar to Docker's progress bars. * modified: nexus/download.go - Adding the library pb - Adding documentation - Adding the struct UrlMetadata that is used during the HTTP HEAD operation to retrieve the length of the resources. - Adding the struct UrlDownload, which has the pointer to the UrlMetadata and the ProgressBar - Adding the struct ResourceSizeDownload, which returns a function that returns the UrlMetadata - Adding the function "collectBarsIndex" will retrieve the length of the files by executing an HTTP HEAD request to build the progress bars in Parallel using the channel. It times out in 1min just in case. - Adding the function retrieveResourceLenth, that executes the HTTP HEAD for the URL and builds the UrlMetadata. - Refactoring the function fanInDownloads to retrieve the progress bars index, create the progress bar pool. After that, it makes the request to nexusDownload in parallel to download the urls. - Removing the old progress channel implementation. - Refactoring the method nexusDownload to take the UrlDownload struct pointer, which carries information about if the URL is broken. If not, it continues with the download and uses the Multi-writer for the progress bar, as described at https://github.com/cheggaaa/pb/tree/multiple#progress-bar-for-io-operations - Refactoring DownloadAllList to remove the progress Channel.
…usted + Last Download to 100% This commit refacts the download and progress to properly handle the last download by waiting for 1sec after the process finishes. It properly fills out the total download. Finally, changing the progress bar library to use the forked version because the current version imposes the locked-terminal. Until it is resolved in the master branch, I will keep my fork. cheggaaa/pb#31 * modified: nexus/download.go - Removing the dependency to the progress libraries, refactored to the progress.go. - Retrieving the instance of the pool - Waiting 1sec to finish the download * modified: nexus/progress.go - Using my personal forked version of the PB library until the locked-terminal version gives the API to choose to not block the terminal. - Updating the docs - Fixing the prefix to be "[ obj.ext ]" - Creating factory methods to properly create the library's version. - Creating the pool based on the parameters.
Any chance you can merge some minimal support for multiple progress bars into master? Doesn't have to satisfy every requirement set in this issue. Just something to give a few progress bars. I can create the PR for you if you wish. |
Merged! |
Merged just in time! 👍 |
@cheggaaa Thanks for great feature and example. Would be great to add package main
import (
"math/rand"
"pb"
"sync"
"time"
)
func main() {
pool := &pb.Pool{}
first := pb.New(1000).Prefix("First ")
second := pb.New(1000).Prefix("Second ")
third := pb.New(1000).Prefix("Third ")
pool.Add(first, second, third)
pool.Start()
wg := new(sync.WaitGroup)
for _, bar := range []*pb.ProgressBar{first, second, third} {
wg.Add(1)
go func(cb *pb.ProgressBar) {
for n := 0; n < 1000; n++ {
cb.Increment()
time.Sleep(time.Millisecond * time.Duration(rand.Intn(100)))
}
cb.Finish()
wg.Done()
}(bar)
}
wg.Wait()
// Stop pool, else keyboard will be locked after execution (as minimum in Ubuntu)
pbPool.Stop()
} |
Problem
Hi there,
I have a list of files being downloaded by different go routines...
I added the
pb()
implementation and it shows the progress bar, but it only displays in the same line...Feature Request
This is similar to Docker's progress bars while pulling images...
thanks!
Marcello
The text was updated successfully, but these errors were encountered: