Coder Social home page Coder Social logo

Comments (20)

cheggaaa avatar cheggaaa commented on August 16, 2024

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.

marcellodesales avatar marcellodesales commented on August 16, 2024

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.

cheggaaa avatar cheggaaa commented on August 16, 2024

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.

marcellodesales avatar marcellodesales commented on August 16, 2024

@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.

cheggaaa avatar cheggaaa commented on August 16, 2024

Good news!
Now we have locked input - b2aef60

Bad news - windows is not yet supported

from pb.

cheggaaa avatar cheggaaa commented on August 16, 2024

Needs to be done:

  • win support
  • sortable bars
  • test on BSD and Solaris systems (i have only mac and linux)

from pb.

marcellodesales avatar marcellodesales commented on August 16, 2024

@cheggaaa I was able to implement the IO-based Progress Bars with the sample you have (this is a real app)...

screen shot 2014-12-17 at 1 45 08 pm

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.

marcellodesales avatar marcellodesales commented on August 16, 2024

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.

marcellodesales avatar marcellodesales commented on August 16, 2024

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.

screen shot 2014-12-18 at 7 21 58 am

from pb.

marcellodesales avatar marcellodesales commented on August 16, 2024

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.

cheggaaa avatar cheggaaa commented on August 16, 2024

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.

cheggaaa avatar cheggaaa commented on August 16, 2024

Can you check last version? Under linux signals works fine

from pb.

marcellodesales avatar marcellodesales commented on August 16, 2024

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.

uetchy avatar uetchy commented on August 16, 2024

Any updates?
I guess that it looks good to merge multiple branch into master.

from pb.

cheggaaa avatar cheggaaa commented on August 16, 2024

So far it's alpha.. We have not windows support and have some problems with catching os signals

from pb.

uetchy avatar uetchy commented on August 16, 2024

Did you checked out go-keybind ? This library can catch user inputs and supports windows.

from pb.

GideonRed-zz avatar GideonRed-zz commented on August 16, 2024

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.

cheggaaa avatar cheggaaa commented on August 16, 2024

Merged!
Code was cleaned and added some safety changes.
But anyway do not work at windows.

from pb.

Quentin-M avatar Quentin-M commented on August 16, 2024

Merged just in time!
We planned to start using it today on the experimental branch.
Thanks!

👍

from pb.

mnvx avatar mnvx commented on August 16, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.