request-vm-on-golem 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,72 @@
1
+ import sys
2
+ import threading
3
+ import time
4
+ import itertools
5
+
6
+ class Spinner:
7
+ """A simple spinner class for CLI progress indication."""
8
+ def __init__(self, message="", delay=0.1):
9
+ self.spinner = itertools.cycle(['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'])
10
+ self.delay = delay
11
+ self.busy = False
12
+ self.spinner_visible = False
13
+ self.message = message
14
+ sys.stdout.write('\033[?25l') # Hide cursor
15
+
16
+ def write_next(self):
17
+ """Write the next spinner frame."""
18
+ with self._screen_lock:
19
+ if not self.spinner_visible:
20
+ sys.stdout.write(f"\r{next(self.spinner)} {self.message}")
21
+ self.spinner_visible = True
22
+ sys.stdout.flush()
23
+
24
+ def remove_spinner(self, cleanup=False):
25
+ """Remove the spinner from the terminal."""
26
+ with self._screen_lock:
27
+ if self.spinner_visible:
28
+ sys.stdout.write('\r')
29
+ sys.stdout.write(' ' * (len(self.message) + 2))
30
+ sys.stdout.write('\r')
31
+ if cleanup:
32
+ sys.stdout.write('\033[?25h') # Show cursor
33
+ sys.stdout.flush()
34
+ self.spinner_visible = False
35
+
36
+ def spinner_task(self):
37
+ """Animate the spinner."""
38
+ while self.busy:
39
+ self.write_next()
40
+ time.sleep(self.delay)
41
+ self.remove_spinner()
42
+
43
+ def __enter__(self):
44
+ """Start the spinner."""
45
+ self._screen_lock = threading.Lock()
46
+ self.busy = True
47
+ self.thread = threading.Thread(target=self.spinner_task)
48
+ self.thread.daemon = True
49
+ self.thread.start()
50
+ return self
51
+
52
+ def __exit__(self, exc_type, exc_val, exc_tb):
53
+ """Stop the spinner and show completion."""
54
+ self.busy = False
55
+ time.sleep(self.delay)
56
+ self.remove_spinner(cleanup=True)
57
+ if exc_type is None:
58
+ # Show checkmark on success
59
+ sys.stdout.write(f"\r✓ {self.message}\n")
60
+ else:
61
+ # Show X on failure
62
+ sys.stdout.write(f"\r✗ {self.message}\n")
63
+ sys.stdout.flush()
64
+
65
+ def step(message):
66
+ """Decorator to add a spinning progress indicator to a function."""
67
+ def decorator(func):
68
+ async def wrapper(*args, **kwargs):
69
+ with Spinner(message):
70
+ return await func(*args, **kwargs)
71
+ return wrapper
72
+ return decorator