halo icon indicating copy to clipboard operation
halo copied to clipboard

Synchronous spinner

Open steelman opened this issue 7 years ago • 7 comments

Support synchronous spinners which switch frames upon explicit request from a working thread like.

with Halo(spinner='dots') as spinner:
  for f in files_to_load():
    spinner.next(text="Loading %s" %f) # or .step(), or .tick(), or…
    do_load_file(f)

This can (as far as I understand) be achieved with .frame() but isn't as concise as the above. Possibly don't render new frame more often than interval.

steelman avatar Feb 16 '18 08:02 steelman

How about this way? I think it can do what you want.

with Halo(spinner='dots') as spinner:
   for f in files_to_load():
        spinner.text = 'Loading {}'.format(f)
        do_load_file(f)

winterjung avatar Feb 16 '18 08:02 winterjung

This isn't a bad solution, however, it doesn't work if there is nothing like a filename to show and I still want the spinner to be updated once a loop.

steelman avatar Feb 16 '18 09:02 steelman

@steelman Thanks for opening this. Could you add an example to your second comment?

manrajgrover avatar May 06 '18 08:05 manrajgrover

Tough question. Nothing in particular comes to my mind, so let my try theoretic cases.

  1. Very long labels which don't hold usable information for users (e.g. cryptographic keys)
  2. An unsorted or infinite set of data (so users can't determine progress)
  3. An event loop or waiting for a network connection to be established.

steelman avatar May 07 '18 05:05 steelman

@steelman I'm getting what you're saying. See, this is what spinner.text is for. If we need to step in every iteration, let's say for percentage, we would need to know the length of the iterable. For that, we need to add a wrapper which handles iterations and updates the text. But we can only do it for iterables.

manrajgrover avatar May 07 '18 06:05 manrajgrover

At this moment halo satisfies my needs so, most probably, I won't develop any solution to the problem I described. However, I imagine, you may want to keep this issue open, so if anybody comes looking for an inspiration for a contribution, they will find one.

steelman avatar May 08 '18 08:05 steelman

Happy to update #132 and check it still works, if the feature might still be of interest @manrajgrover?

foster999 avatar Sep 05 '20 16:09 foster999