diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 39dc5440..1557f895 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -22,10 +22,11 @@
-
+
+
-
-
+
+
@@ -486,20 +487,6 @@
1605881914521
-
- 1608059501153
-
-
-
- 1608059501153
-
-
- 1608066984496
-
-
-
- 1608066984496
-
1608070231599
@@ -829,7 +816,21 @@
1614838148219
-
+
+ 1614896688665
+
+
+
+ 1614896688665
+
+
+ 1614896795653
+
+
+
+ 1614896795653
+
+
@@ -845,8 +846,6 @@
-
-
@@ -870,7 +869,9 @@
-
+
+
+
diff --git a/src/cpl/console/console.py b/src/cpl/console/console.py
index 51f02b2d..5fc04b09 100644
--- a/src/cpl/console/console.py
+++ b/src/cpl/console/console.py
@@ -1,4 +1,6 @@
import os
+import sys
+from collections import Callable
from typing import Union, Optional
import pyfiglet
@@ -7,6 +9,7 @@ from termcolor import colored
from cpl.console.background_color import BackgroundColor
from cpl.console.foreground_color import ForegroundColor
+from cpl.console.spinner_thread import SpinnerThread
class Console:
@@ -203,3 +206,16 @@ class Console:
if not cls._is_first_write:
cls._output('', end='')
cls._output(string, x, y, end='')
+
+ @classmethod
+ def spinner(cls, message: str, call: Callable):
+ cls.write(message)
+ spinner = SpinnerThread(cls)
+ spinner.start()
+ call()
+ spinner.stop_spinning()
+ cls.write_line()
+
+ @classmethod
+ def flush(cls):
+ sys.stdout.flush()
diff --git a/src/cpl/console/spinner_thread.py b/src/cpl/console/spinner_thread.py
new file mode 100644
index 00000000..bcca170a
--- /dev/null
+++ b/src/cpl/console/spinner_thread.py
@@ -0,0 +1,31 @@
+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:
+ spinner = self._spinner()
+ while self._is_spinning:
+ self._console.write(next(spinner))
+ time.sleep(0.1)
+ self._console.write('\b')
+ self._console.flush()
+
+ self._console.write(' ')
+
+ def stop_spinning(self):
+ self._is_spinning = False
+ time.sleep(0.1)