39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
import time
|
|
from os import get_terminal_size
|
|
from colored import fg, bg, attr # para los colores
|
|
from time import sleep
|
|
|
|
|
|
def sending_file_progress(filename: bytes, size: int, sent: int) -> None:
|
|
# float(sent) / float(size) * 100
|
|
green_scale = [28, 34, 40, 76, 82, 118]
|
|
loading_chars = "|/-\\"
|
|
_filename = filename.decode()
|
|
screen_size = get_terminal_size()
|
|
cols = int(screen_size.columns / 100 * 50)
|
|
|
|
percent = int(float(sent) / float(size) * 100)
|
|
_n = percent % len(loading_chars)
|
|
|
|
_color: int
|
|
_color_picker = int((percent / 10) * (len(green_scale) / 10))
|
|
|
|
space_filling = " " * int(100 - percent / (100 * cols)) + " "
|
|
load_bar = f'{"=" * int(percent / 100 * cols)}=>'
|
|
|
|
if int(percent) >= 100:
|
|
_color = green_scale[len(green_scale) - 1]
|
|
else:
|
|
_color = green_scale[_color_picker]
|
|
print(
|
|
f'\t[{loading_chars[_n]}] {fg(_color)}{load_bar}{attr("reset")} [{percent}%] {space_filling} [{(_filename[:75] + "..") if len(_filename) > 75 else _filename}]',
|
|
end='\r')
|
|
|
|
|
|
x = 0
|
|
while x <= 100:
|
|
sending_file_progress(b"file", 100, x) # bytes string, not flat string
|
|
time.sleep(0.05)
|
|
x += 1
|
|
print()
|