-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
first version, copied from pallets/click#649
- Loading branch information
Yoav Ram
committed
Sep 4, 2016
0 parents
commit 019cf1e
Showing
10 changed files
with
2,416 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
click_spinner/_version.py export-subst |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.idea | ||
.DS_Store | ||
*.pyc | ||
*.pyo | ||
*.egg-ignore | ||
*.egg-info | ||
dist | ||
build | ||
docs/_build | ||
click.egg-info | ||
.tox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
include versioneer.py | ||
include click_spinner/_version.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Click Spinner | ||
|
||
Sometimes you would just like to show the user some progress, | ||
but a progress bar is not suitable because you don’t know how much longer it would take. | ||
In these cases you might want to display a simple spinner using the `spinner()` function. | ||
|
||
Example usage: | ||
|
||
```py | ||
with click_spinner.spinner(): | ||
do_something() | ||
do_something_else() | ||
``` | ||
|
||
It looks like this: | ||
|
||
![spinner](https://cloud.githubusercontent.com/assets/1288133/18229827/29629cd4-728f-11e6-8007-6c85ac50565c.gif) | ||
|
||
Spinner class based on on a [gist by @cevaris](https://gist.github.com/cevaris/79700649f0543584009e). | ||
|
||
Introduced in [PR #649](https://github.com/pallets/click/pull/649). | ||
|
||
## Install | ||
|
||
``` | ||
pip install click-spinner | ||
``` | ||
|
||
## Authors | ||
|
||
- Yoav Ram (@yoavram) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from builtins import next | ||
from builtins import object | ||
import sys | ||
import threading | ||
import time | ||
import itertools | ||
|
||
|
||
class Spinner(object): | ||
spinner_cycle = itertools.cycle(['-', '/', '|', '\\']) | ||
|
||
def __init__(self): | ||
self.stop_running = threading.Event() | ||
self.spin_thread = threading.Thread(target=self.init_spin) | ||
|
||
def start(self): | ||
self.spin_thread.start() | ||
|
||
def stop(self): | ||
self.stop_running.set() | ||
self.spin_thread.join() | ||
|
||
def init_spin(self): | ||
while not self.stop_running.is_set(): | ||
sys.stdout.write(next(self.spinner_cycle)) | ||
sys.stdout.flush() | ||
time.sleep(0.25) | ||
sys.stdout.write('\b') | ||
|
||
def __enter__(self): | ||
self.start() | ||
|
||
def __exit__(self, exc_type, exc_val, exc_tb): | ||
self.stop() | ||
|
||
|
||
def spinner(): | ||
"""This function creates a context manager that is used to display a | ||
spinner as long as the context has not exited. | ||
Example usage:: | ||
with spinner(): | ||
do_something() | ||
do_something_else() | ||
""" | ||
return Spinner() | ||
|
||
|
||
from ._version import get_versions | ||
__version__ = get_versions()['version'] | ||
del get_versions |
Oops, something went wrong.