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

Fixes #56: Add placement parameter that allows spinner on right side of text #57

Merged
merged 4 commits into from
May 8, 2018
Merged

Fixes #56: Add placement parameter that allows spinner on right side of text #57

merged 4 commits into from
May 8, 2018

Conversation

stephen-bunn
Copy link
Contributor

Description of new feature, or changes

Adds the placement parameter which allows placement of the spinner on either the right or left side of the text using the values right and left.
Defaults to left

The only real logic changes are checking if the placement value is set to right and then switching the text and spinner frames in a str.fomat call.

# simple usage
with Halo(text='Spinning...', placement='right') as spinner:
    time.sleep(1)

Spinning... ⠧


# invalid placements raise ValueError
with Halo(text='Spinning...', placement='invalid') as spinner:
    time.sleep(1)

Traceback (most recent call last):
  File "main.py", line 4, in <module>
    with Halo('foobar', placement='invalid') as sp:
  File "C:\Users\r\Documents\GitHub\halo\halo\halo.py", line 70, in __init__
    self.placement = placement
  File "C:\Users\r\Documents\GitHub\halo\halo\halo.py", line 193, in placement
    raise ValueError("unknown spinner placement '{0}', available are {1}".format(placement, self.SPINNER_PLACEMENTS))
ValueError: unknown spinner placement 'invalid', available are ('left', 'right')

Opening additional PR (previous #52) because original repo was removed.

Checklist

  • Your branch is up-to-date with the base branch
  • You've included at least one test if this is a new feature
  • All tests are passing

Related Issues and Discussions

Fixes: #56
Closes: #52

People to notify

@manrajgrover

- Defaults to `left`
- Allows both `left` and `right`
- When set to `right` will display spinner on right side of text
Copy link
Owner

@manrajgrover manrajgrover left a comment

Choose a reason for hiding this comment

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

@stephen-bunn I've added few comments which might need attention. Rest looks good to me. Could you please check why tests are failing on Appveyor?

@@ -63,6 +67,7 @@ def __init__(self, text='', color='cyan', spinner=None, animation=None, interval
if not stream:
stream = sys.stdout

self.placement = placement
Copy link
Owner

Choose a reason for hiding this comment

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

self.placement -> self._placement

Defines the placement of the spinner
"""
if placement not in self.SPINNER_PLACEMENTS:
raise ValueError("unknown spinner placement '{0}', available are {1}".format(placement, self.SPINNER_PLACEMENTS))
Copy link
Owner

Choose a reason for hiding this comment

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

unknown -> Unknown

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you like the idea of raising ValueError on unknown placements?
The reason line 70 is self.placement = placement (not self._placement = placement) is because it calls this setter method which runs the snippet above.

I can simply remove the logic in the setter and say any placement that isn't right is assumed to be left.

Copy link
Owner

Choose a reason for hiding this comment

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

No, it makes sense to throw an error. This is correct.

"""Test right placement of spinner.
"""
spinner = Halo(text='foo', placement='right', stream=self._stream)
spinner.start()
Copy link
Owner

Choose a reason for hiding this comment

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

I would suggest you add a time.sleep between .start and .succeed which will not stop the spinner immediately and there would be output that you can assert on. Perhaps this is the reason why test is failing on Appveyor. Get the output after time.sleep and succeeding.

output = self._get_test_output(spinner)

(text, _) = output[-1].split(" ")
self.assertEqual(text, "foo")
Copy link
Owner

Choose a reason for hiding this comment

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

Likewise here. Could you please debug this?

- adding time.sleep after `spinner.start` calls in tests
Copy link
Owner

@manrajgrover manrajgrover left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you for working on this @stephen-bunn and for your patience. 💯

@manrajgrover manrajgrover merged commit 8a32d27 into manrajgrover:master May 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants