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

Log output on top of spinner #36

Closed
smackesey opened this issue Oct 1, 2019 · 4 comments
Closed

Log output on top of spinner #36

smackesey opened this issue Oct 1, 2019 · 4 comments

Comments

@smackesey
Copy link

Thanks for a great library! A request: I'd like to be able to log output above the spinner while keeping the spinner going uninterrupted at the bottom of the screen. So far as I can tell this library does not support this behavior. The closest I've gotten is the following code:

spinner = TTY::Spinner.new("[:spinner] Logging output ...")
spinner.auto_spin
(1..5).each { |i| puts "\r#{i}"; sleep 1 }
spinner.stop('done')

But the message only overwrites part of the spinner. And if the lines are coming too fast, it does not work at all (i.e. the spinner doesn't seem to get redrawn on the bottom line):

spinner = TTY::Spinner.new("[:spinner] Logging output ...")
spinner.auto_spin
(1..1000).each { |i| puts "\r#{i}"; sleep 0.01 }
spinner.stop('done')
@piotrmurach
Copy link
Owner

Hi Sean,

Thanks for using this gem and contributing!

I'm in for adding logging to print information. Would you have time to add log method on the spinner instance? It could be configurable to let the user choose whether they want messages above or below. Let's say the above would be the default. Do you have time?

@icy-arctic-fox
Copy link

I have been able to achieve this fairly reliably by using Spinner#clear_line and immediately printing the output. Perhaps something like that could be used in the implementation. It would probably be more involved for the multi-spinner.

spinner.auto_spin
sleep 3
spinner.clear_line
puts 'log output'
sleep 3
spinner.success('Done')

@piotrmurach
Copy link
Owner

@smackesey I know it's a while but I finally got around to work on this issue. There is a log method in the master branch that handles logging of any multiline text above the spinner animation. Your example with a small adjustment should work now:

spinner = TTY::Spinner.new("[:spinner] Logging output ...")
spinner.auto_spin
(1..5).each { |i| spinner.log("\r#{i}"); sleep 1 }
spinner.stop('done')

@piotrmurach
Copy link
Owner

@icy-arctic-fox There is a new log method in the master branch that handles displaying multiline content above a spinner animation. Your example can now be written as follows:

spinner.auto_spin
sleep 3
spinner.log "log output"
sleep 3
spinner.success("Done")

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