Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to indent spinners #153

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions examples/indent_spin.py
Original file line number Diff line number Diff line change
@@ -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()

8 changes: 6 additions & 2 deletions halo/halo.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def __init__(
interval=-1,
enabled=True,
stream=sys.stdout,
indent="",
):
"""Constructs the Halo object.
Parameters
Expand Down Expand Up @@ -96,6 +97,7 @@ def __init__(
self._stop_spinner = None
self._spinner_id = None
self.enabled = enabled
self.indent = indent

environment = get_environment()

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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]
)

Expand Down
11 changes: 11 additions & 0 deletions tests/test_halo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down