halo icon indicating copy to clipboard operation
halo copied to clipboard

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

Open danieltdp opened this issue 8 years ago • 8 comments

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

danieltdp avatar Oct 03 '17 21:10 danieltdp

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

bertokhoury avatar Oct 18 '17 14:10 bertokhoury

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

manrajgrover avatar Oct 18 '17 17:10 manrajgrover

@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

winterjung avatar Dec 29 '17 02:12 winterjung

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

manrajgrover avatar Dec 29 '17 08:12 manrajgrover

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

thisHermit avatar Oct 04 '19 05:10 thisHermit

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

JustinTervala avatar Oct 29 '20 18:10 JustinTervala

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

manrajgrover avatar Oct 29 '20 20:10 manrajgrover

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

JustinTervala avatar Nov 12 '20 20:11 JustinTervala