From 0b9fe77851d3591ac9384aef7a3a5ed658ed2428 Mon Sep 17 00:00:00 2001 From: Pradhyum R Date: Fri, 18 Sep 2020 21:30:30 -0400 Subject: [PATCH 1/2] Added ability to indent spinners --- examples/indent_spin.py | 7 +++++++ halo/halo.py | 8 ++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 examples/indent_spin.py diff --git a/examples/indent_spin.py b/examples/indent_spin.py new file mode 100644 index 0000000..6b0d611 --- /dev/null +++ b/examples/indent_spin.py @@ -0,0 +1,7 @@ +from halo import Halo +from time import sleep + +with Halo(text="Look at that bullet!", indent=" • ") as s: + sleep(1) + s.succeed() + diff --git a/halo/halo.py b/halo/halo.py index 9e10b66..96996d7 100644 --- a/halo/halo.py +++ b/halo/halo.py @@ -51,6 +51,7 @@ def __init__( interval=-1, enabled=True, stream=sys.stdout, + indent="", ): """Constructs the Halo object. Parameters @@ -96,6 +97,7 @@ def __init__( self._stop_spinner = None self._spinner_id = None self.enabled = enabled + self.indent = indent environment = get_environment() @@ -439,7 +441,8 @@ def frame(self): self._frame_index = self._frame_index % len(frames) text_frame = self.text_frame() - return "{0} {1}".format( + return "{0}{1} {2}".format( + self.indent, *[ (text_frame, frame) if self._placement == "right" @@ -597,7 +600,8 @@ def stop_and_persist(self, symbol=" ", text=None): self.stop() - output = "{0} {1}\n".format( + output = "{0}{1} {2}\n".format( + self.indent, *[(text, symbol) if self._placement == "right" else (symbol, text)][0] ) From 20e24023502846414e06739168fff935f307e147 Mon Sep 17 00:00:00 2001 From: Pradhyum R Date: Fri, 18 Sep 2020 21:54:23 -0400 Subject: [PATCH 2/2] Added ability to indent spinners --- tests/test_halo.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/test_halo.py b/tests/test_halo.py index 29918aa..b2315da 100644 --- a/tests/test_halo.py +++ b/tests/test_halo.py @@ -622,6 +622,17 @@ def test_redirect_stdout(self): self.assertIn('foo', output[0]) + def test_indent(self): + """Test indents spinner + """ + indent = " " + spinner = Halo(text="spam", spinner="dots", indent=indent, stream=self._stream) + spinner.start() + spinner.stop() + output = self._get_test_output()["text"] + print(f"\t\tDEBUG: {output}") + self.assertEqual(indent, output[0][:len(indent)]) + def tearDown(self): pass