#!/usr/bin/env python3
# ------------------------------------------------------------------------------
# progressbar.py
# ==============
#
# Scope Native
# Copyright (C) 2024 by RaySoft, Zurich, Switzerland
# License GNU General Public License (GPL) 2.0
# https://www.gnu.org/licenses/gpl2.txt
#
# ------------------------------------------------------------------------------
COUNT = 618
# ------------------------------------------------------------------------------
from shutil import get_terminal_size
from time import sleep
from sys import exit
# ------------------------------------------------------------------------------
def main():
# Get the length of the progress bar
bar_lenght = int(get_terminal_size()[0]) - 12
# Do something for 'COUNT' times e.g convert 'COUNT' files
for i in range(COUNT + 1):
# Print the percentage and the progress bar
print('\r{0:>4.0%} |{1:{2}s}|'.format(i / COUNT,
int(bar_lenght * i / COUNT) * '=', bar_lenght), end='')
# Just for demo purposes
sleep(0.01)
print(' Done')
return 0
# ------------------------------------------------------------------------------
if __name__ == '__main__':
return_value = main()
exit(return_value)