Skip to content
Open
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: 6 additions & 1 deletion halo/halo.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ def _get_spinner(self, spinner):
Contains frames and interval defining spinner
"""
default_spinner = Spinners['dots'].value
windows_spinners = ['balloon', 'balloon2', 'bouncingBar', 'dqpb', 'flip', 'layer', 'line', 'pipe',
'simpleDots', 'simpleDotsScrolling', 'star2', 'shark', 'toggle13']

if spinner and type(spinner) == dict:
return spinner
Expand All @@ -271,7 +273,10 @@ def _get_spinner(self, spinner):
else:
return default_spinner
else:
return Spinners['line'].value
if all([is_text_type(spinner), spinner in Spinners.__members__, spinner in windows_spinners]):
return Spinners[spinner].value
else:
return Spinners['line'].value

def _get_text(self, text):
"""Creates frames based on the selected animation
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
coverage==4.4.1
nose==1.3.7
pylint==1.7.2
pylint==1.9.4
tox==2.8.2
twine==1.12.1
27 changes: 27 additions & 0 deletions tests/test_halo.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,33 @@ def test_redirect_stdout(self):

self.assertIn('foo', output[0])

def test_windows_whitelist(self):
"""Test whitelist of Windows-compatible spinners
"""
if not is_supported():
instance = Halo()
default_spinner_value = "line"

instance.spinner = default_spinner_value
self.assertEqual(default_spinner, instance.spinner)

instance.spinner = "balloon"
self.assertEqual(Spinners['balloon'].value, instance.spinner)

instance.spinner = "monkey"
self.assertEqual(default_spinner, instance.spinner)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add test where we render the frames in windows environment and check if they are working correctly?

@JoseALermaIII JoseALermaIII Apr 19, 2019

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I saw a similar test higher up. I'll check if it can be implemented in Windows

spinner = Halo(text='foo', spinner='balloon2', stream=self._stream)
frames_ = [get_coded_text(frame_) for frame_ in Spinners['balloon2'].value['frames']]

spinner.start()
time.sleep(1)
spinner.stop()
output = self._get_test_output()['text']

for i in range(len(frames_)):
self.assertEqual(output[i], '{0} foo'.format(frames_[i]))

def tearDown(self):
pass

Expand Down