2021-03-05 15:55:14 +01:00
|
|
|
import threading
|
|
|
|
import time
|
|
|
|
|
|
|
|
|
|
|
|
class SpinnerThread(threading.Thread):
|
|
|
|
|
|
|
|
def __init__(self, console):
|
|
|
|
threading.Thread.__init__(self)
|
|
|
|
|
|
|
|
self._console = console
|
|
|
|
self._is_spinning = True
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _spinner():
|
|
|
|
while True:
|
|
|
|
for cursor in '|/-\\':
|
|
|
|
yield cursor
|
|
|
|
|
|
|
|
def run(self) -> None:
|
2021-03-05 16:27:38 +01:00
|
|
|
self._console.write('\t')
|
2021-03-05 15:55:14 +01:00
|
|
|
spinner = self._spinner()
|
|
|
|
while self._is_spinning:
|
|
|
|
self._console.write(next(spinner))
|
|
|
|
time.sleep(0.1)
|
|
|
|
self._console.write('\b')
|
2021-03-05 16:27:38 +01:00
|
|
|
|
2021-03-05 15:55:14 +01:00
|
|
|
self._console.flush()
|
|
|
|
|
|
|
|
self._console.write(' ')
|
|
|
|
|
|
|
|
def stop_spinning(self):
|
|
|
|
self._is_spinning = False
|
|
|
|
time.sleep(0.1)
|