Comments (20)
Hi!
I made commit with experimental support
It's based on ANSI Escape Sequences
Checkout this branch https://github.com/cheggaaa/pb/tree/multiple
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
from pb.
Hi @cheggaaa...
Thanks a lot for making this!!! The example works... Other suggestions to improve it:
- Block any terminal key to be ENTERED other than Ctrl+C
- Add this as an example in the examples directory
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!
from pb.
Block any terminal key to be ENTERED other than Ctrl+C
This not easy.. want to do this without heavy dependencies like ncurses.
If we'll know absolute cursor position, we can change only necessary rows without locking normal input and output. Until i can't found solution of this problem.
from pb.
@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...
from pb.
Good news!
Now we have locked input - b2aef60
Bad news - windows is not yet supported
from pb.
Needs to be done:
- win support
- sortable bars
- test on BSD and Solaris systems (i have only mac and linux)
from pb.
@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!!!
from pb.
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...
from pb.
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.
from pb.
Reason for the problem
if 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 Workaround
If 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...
from pb.
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).
I'm doing it now.
About many bars. I think user has no need more than 5-6 bars) and problems like queues should solve user.
from pb.
Can you check last version? Under linux signals works fine
from pb.
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...
from pb.
Any updates?
I guess that it looks good to merge multiple
branch into master.
from pb.
So far it's alpha.. We have not windows support and have some problems with catching os signals
from pb.
Did you checked out go-keybind ? This library can catch user inputs and supports windows.
from pb.
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.
from pb.
Merged!
Code was cleaned and added some safety changes.
But anyway do not work at windows.
from pb.
Merged just in time!
We planned to start using it today on the experimental branch.
Thanks!
👍
from pb.
@cheggaaa Thanks for great feature and example. Would be great to add pbPool.Stop()
into end of 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()
// Stop pool, else keyboard will be locked after execution (as minimum in Ubuntu)
pbPool.Stop()
}
from pb.
Related Issues (20)
- Elapsed Time HOT 1
- Version Error HOT 1
- Not display console HOT 4
- Progress bars rendering is disturbed when terminal screen size is small
- feature req: ProxyReadSeeker HOT 2
- How can I clean the process bar before I want to output something. HOT 6
- It is "go get github.com/cheggaaa/pb/v3" error?
- Spinner HOT 2
- Flag to disable the counter total output HOT 1
- [Question]: How to use more colors? HOT 1
- Incorrect values of downloaded and percentage HOT 1
- possibility to update ProgressBar from worker pool HOT 3
- [QUESTION] How to get multiple/single progressbars for concurrent processes ? HOT 1
- Progress additional text at speed section incorrect work HOT 2
- Building Windows binary on 3.1.3 fails HOT 1
- Disable when no TTY? HOT 2
- ProgressBar Pool on Windows: Inconsistent printing on Windows when using ProgressBarTemplate HOT 4
- Copyright confusion HOT 2
- How to display a progress w/ speed that slower than one item per second?
- Nested loop printout HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pb.