manrajgrover / halo

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

Inject spinner instance as parameter to decorated function #137

Closed romnn closed 2 years ago

romnn commented 4 years ago

I propose to inject the spinner instance as an optional parameter to functions decorated by halo. This was my use case:

@Halo(text='Doing work', spinner='dots', color="red")
def initialize_git(spinner=None):  # This argument is optional and can also be omitted
    try:
        my_complicated_function()
    except Exception:
        spinner.fail("Failed!")
        raise
    spinner.succeed("Succeeded!")

I know that this is possible to use a context manager, but this does require deeper nesting and is not that neat imo. Please let me know if you consider this a valid use case.

Description

This PR adds functionality to declare the optional keyword argument as a parameter to obtain a reference to the spinner object. This does not break anything and is completely optional.

Checklist

Further considerations

It is also possible to inject the spinner instance as a positional argument, but this could not be made optional.

coveralls commented 4 years ago

Pull Request Test Coverage Report for Build 424


Totals Coverage Status
Change from base Build 422: 0.0%
Covered Lines:
Relevant Lines: 0

💛 - Coveralls