From e00f98ab2de09b0afd47b4835bebeb00fb88907f Mon Sep 17 00:00:00 2001 From: William Brockhus Date: Fri, 10 Feb 2023 16:20:34 +1100 Subject: [PATCH] feat: @halo wrapped function can accept spinner parameter --- halo/halo.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/halo/halo.py b/halo/halo.py index 9e10b66..898beb8 100644 --- a/halo/halo.py +++ b/halo/halo.py @@ -128,8 +128,16 @@ def __call__(self, f): @functools.wraps(f) def wrapped(*args, **kwargs): - with self: - return f(*args, **kwargs) + try: + if 'spinner' in f.__code__.co_varnames[:f.__code__.co_argcount]: + with self as h: + return f(spinner=h, *args, **kwargs) + else: + with self: + return f(*args, **kwargs) + except ValueError: + with self: + return f(*args, **kwargs) return wrapped