-
-
Notifications
You must be signed in to change notification settings - Fork 227
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
feat: make progressbar could update according to an interval or updat… #199
Conversation
…e each time render was called.
Thanks for the edit, it looks like it is failing tests? |
Yes. It is failing tests. It's because I changed the default setting of the progress bar. If you used the spinner, than the progress bar will change by a time interval by default and it makes the output a great difference from the test. In my opinion,the old way to change the spinner do really cannot change the spinner properly. In the original code,the spinner change each 100ms, and if you don't render it, you cannot see that change. That's why those issue was caused. For example,try this code: package main
import (
"fmt"
"github.com/schollz/progressbar/v3"
"time"
)
func main() {
bar := progressbar.NewOptions(-1,
progressbar.OptionSetDescription("test"),
progressbar.OptionSpinnerType(7))
for i := 0; i < 10; i++ {
bar.Describe(fmt.Sprintf("test"))
time.Sleep(400 * time.Millisecond)
}
} You will realized that spinner never changed. Becuase the spinner type 7: {"◐", "◓", "◑", "◒"}, it have 4 different character. So if the interval of render is 400ms, each time when we render it, the spinner would always be "◐". I think it should be changed, the old logic is a defect for most of the users I guess. I'm also wondering if I should change the default form, perhaps causing some negative effect the use of some developers in the past. But if you let me make a choice, I think I will change it. I don't think anyone would use the output of progressbar as a part of their logic in the application.🤔 And most of the failed tests are because of the extra output from the goroutine, which was cleaned by '\r \r'. Like my screenshot shows, I rendered more times and the output in the buffer would be much longer. But if it is output to stdout, they will be the same. I think the test should base on the extra output. For example, if we expect to see the progressbar to be cleaned. Than what we need is to check whether the actual output is empty, not check whether the string in the buffer is equals to this
I am currently struggle with it, I will create a project, create a tool which makes it possible for us to know what the output will be according to the buffer. Simulating the stdout, make those bytes cleaned by '\r \r' could be ignored. Sorry about my barren language expression.🥲 I've already tried my best. |
Yeah I understand. I would happily accept the change - as long as you update the tests to pass I would be able to merge. |
Thank you.🫡 |
update go version
… change goroutine.
… in the terminal.
Well, I gonna say that a lot of words I've told about the tests are wrong. It's actually I've not realized that only when the max = -1 , the ignoreLength is true, than we should render the spinner.🤓 Confident and stupid. |
not stupid at all! this is a fantastic patch, great idea of breaking out the |
Yes,hhh |
Amazing, thanks!!! |
This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [github.com/schollz/progressbar/v3](https://redirect.github.com/schollz/progressbar) | `v3.15.0` -> `v3.16.0` | [![age](https://developer.mend.io/api/mc/badges/age/go/github.com%2fschollz%2fprogressbar%2fv3/v3.16.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/go/github.com%2fschollz%2fprogressbar%2fv3/v3.16.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/go/github.com%2fschollz%2fprogressbar%2fv3/v3.15.0/v3.16.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/go/github.com%2fschollz%2fprogressbar%2fv3/v3.15.0/v3.16.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>schollz/progressbar (github.com/schollz/progressbar/v3)</summary> ### [`v3.16.0`](https://redirect.github.com/schollz/progressbar/releases/tag/v3.16.0) [Compare Source](https://redirect.github.com/schollz/progressbar/compare/v3.15.0...v3.16.0) #### What's Changed - feat: make progressbar could update according to an interval or updat… by [@​chengxilo](https://redirect.github.com/chengxilo) in [https://github.com/schollz/progressbar/pull/199](https://redirect.github.com/schollz/progressbar/pull/199) **Full Changelog**: schollz/progressbar@v3.15.0...v3.16.0 </details> --- ### Configuration 📅 **Schedule**: Branch creation - "after 10pm every weekday,before 5am every weekday,every weekend" (UTC), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/nobl9/sloctl). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC44MC4wIiwidXBkYXRlZEluVmVyIjoiMzguODAuMCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiZGVwZW5kZW5jaWVzIiwiZ29sYW5nIiwicmVub3ZhdGUiXX0=--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Hi, I write some code to solve the problem that is happend to some issues, such as #166 and #141 .
According to the previous code. I set the progressbar to update per 100 * time.Millisecond by default. If user do not want to start a go routine and update it repeatly, it could be set to zero. It works pretty well and seems nice, you can try it with the code in #166 and #141 .
But this feature cannot pass the test because the \r escape character cannot be parsed if we use buffer. I do not know how to handle this kind of problem actually.
For example, this is an Failed test.
Maybe we need to create a function to handle this problem. In the test, use a buffer to cache the output ,and then use a function to parse the string to what we will see in the terminal.
This PR may need further development. Unless it will cause some of the test function noneffective.