2021.4 #19

Merged
edraft merged 237 commits from 2021.4 into master 2021-04-01 10:13:33 +02:00
2 changed files with 17 additions and 7 deletions
Showing only changes of commit ae4709b0d4 - Show all commits

View File

@ -265,7 +265,7 @@ class Console:
cls.write_line(message) cls.write_line(message)
cls.set_hold_back(True) cls.set_hold_back(True)
spinner = SpinnerThread(spinner_foreground_color, spinner_background_color) spinner = SpinnerThread(len(message), spinner_foreground_color, spinner_background_color)
spinner.start() spinner.start()
return_value = call(*args) return_value = call(*args)
spinner.stop_spinning() spinner.stop_spinning()

View File

@ -1,3 +1,4 @@
import os
import sys import sys
import threading import threading
import time import time
@ -10,13 +11,15 @@ from cpl.console.foreground_color import ForegroundColor
class SpinnerThread(threading.Thread): class SpinnerThread(threading.Thread):
def __init__(self, foreground_color: ForegroundColor, background_color: BackgroundColor): def __init__(self, msg_len: int, foreground_color: ForegroundColor, background_color: BackgroundColor):
threading.Thread.__init__(self) threading.Thread.__init__(self)
self._is_spinning = True self._msg_len = msg_len
self._foreground_color = foreground_color self._foreground_color = foreground_color
self._background_color = background_color self._background_color = background_color
self._is_spinning = True
@staticmethod @staticmethod
def _spinner(): def _spinner():
while True: while True:
@ -34,15 +37,22 @@ class SpinnerThread(threading.Thread):
return color_args return color_args
def run(self) -> None: def run(self) -> None:
print('\t', end='') rows, columns = os.popen('stty size', 'r').read().split()
end_msg = 'done'
columns = int(columns) - self._msg_len - len(end_msg)
print(f'{"" : >{columns}}', end='')
spinner = self._spinner() spinner = self._spinner()
while self._is_spinning: while self._is_spinning:
print(colored(next(spinner), *self._get_color_args()), end='') print(colored(f'{next(spinner): >{len(end_msg)}}', *self._get_color_args()), end='')
time.sleep(0.1) time.sleep(0.1)
print('\b', end='') back = ''
for i in range(0, len(end_msg)):
back += '\b'
print(back, end='')
sys.stdout.flush() sys.stdout.flush()
print(colored('done', *self._get_color_args()), end='') print(colored(end_msg, *self._get_color_args()), end='')
def stop_spinning(self): def stop_spinning(self):
self._is_spinning = False self._is_spinning = False