manrajgrover / halo

💫 Beautiful spinners for terminal, IPython and Jupyter
MIT License
2.89k stars 149 forks source link

Provide option to render more than one spinner at the same time #17

Open danieltdp opened 7 years ago

danieltdp commented 7 years ago

Suppose you get multiple long tasks at hand. It should be nice to be able to start more than one spinner before finishing the last one

take this as an example:

 from halo import Hal

 a = start_task_a()
 a_spinner = Halo({'text': 'Do A', 'spinner': 'dots'})
 a_spinner.start()
 a_is_spinning = True

 b = start_task_b()
 b_spinner = Halo({'text': 'Do B', 'spinner': 'dots'})
 b_spinner.start()
 b_is_spinning = True

 while a_is_spinning or b_is_spinning:
     if a.is_finished():
         a_spinner.succeed()
         a_is_spinning = False
     if b.is_finished():
         b_spinner.succeed()
         b_is_spinning = False
bertokhoury commented 7 years ago

@ManrajGrover maybe one simply needs to initialize that if two spinners are spinning. Then, simply print a new line betweem them?

manrajgrover commented 7 years ago

@bertokhoury It can surely be tried. I was also looking to explore how other libraries do the same thing. listr is one of them. Do let me know if you get a chance to implement your solution. Also, feel free to send a PR for the same. 😄

winterjung commented 6 years ago

@ManrajGrover I found that they use list and line counter to push string, render and clear in listr→listr-update-renderer→log-update→ansi-escapes. How about wrapping frame in something like output?

example

# render
output = ['/ First task', '- Second task', '+ Last task']
stream.write('\n'.join(output))
# output maybe
# / First task
# - Second task
# + Last task

# clear
line_count = len(output)
for i in range(line_count):
    stream.write('\r')
    stream.write(CLEAR_LINE)
    stream.write('\033[1A')  # Move the cursor up 1 line

refer

ansi-escapes source

manrajgrover commented 6 years ago

@JungWinter That is such a clever solution! I guess we can support that. We would need to think of a design to accommodate this considering each spinner has its own thread and we would need to get the frame from each spinner before rendering. Let me know if you have already thought about the same.

thisHermit commented 5 years ago

I would like to work on this issue. @manrajgrover could you assign me on this?

JustinTervala commented 4 years ago

Any updates on this feature? I would like to use something like this

manrajgrover commented 4 years ago

@JustinTervala there seems to be some progress in #155 which implements something similar. Have a look at the PR to see if it meets your requirement.

JustinTervala commented 4 years ago

https://github.com/manrajgrover/halo/pull/155 looks like it would work for me.