Skip to main content

A simple console-based loading bar for Python.

Project description

UltraEZLoadingBar

UltraEZLoadingBar is a simple Python package that displays a loading bar in the console.


Installation

To install the package, use pip:

pip install UltraEZLoadingBar

loading_bar Function

Purpose:

Displays a horizontal loading bar with optional color support and a customizable message.

Arguments:

  • steps (int): Total number of steps (e.g., iterations).
  • bar_length (int): The length of the loading bar in characters.
  • delay_per_step (float): The delay between each step (in seconds).
  • message (str): The message to display before the loading bar.
  • color (str): Optional. Adds color to the loading bar using ANSI escape codes. Examples: "r" (red), "g" (green), "b" (blue), etc.

Usage:

  1. Create a loading bar with 100 steps, 100 characters, a 0.1 second delay, and a red message:

    loading_bar(100, 100, 0.1, "Loading... ", "r")
    
  2. Create a loading bar with 100 steps, 100 characters, a 0.1 second delay, and a default color:

    loading_bar(100, 100, 0.1, "Processing... ")
    

    (If you don't want any color, omit the color argument, or pass "" for no text.)


enhancedloading_bar Function

Purpose:

Displays a horizontal loading bar with estimated time remaining.

Arguments:

  • steps (int): Total number of steps.
  • bar_length (int): The length of the loading bar in characters.
  • delay_per_step (float): The delay between each step (in seconds).
  • message (str): The message to display before the loading bar.
  • color (str): Optional. Adds color to the loading bar using ANSI escape codes. Examples: "r" (red), "g" (green), "b" (blue), etc.

Usage:

  1. Create a loading bar with 100 steps, 100 characters, a 0.1 second delay, and a red message:
    enhancedloading_bar(100, 100, 0.1, "Loading... ", "r")
    

new_line Function

Purpose:

Creates a new line in the console.

Usage:

new_line()

colored_text Function

Purpose:

Prints the given text in the specified color.

Arguments:

  • text (str): The text to be printed.
  • color (str): The color of the text. Available colors: "red", "green", "blue", "yellow", "magenta", "cyan", "white", etc.

Usage:

Print "Hello!" in blue:

colored_text("Hello!", "blue")

cls Function

Purpose:

Clears the console screen.

Usage:

cls()

generatekey Function

Purpose:

Generates a random key using the Fernet cryptography system and returns it as a string.

Returns:

  • A random key string (e.g., '...your_key...').

Usage:

key = generatekey()
print(key)

Output:

V2s4RwnK5mc4Ul_w4vXJgzk1cIUGQDOz5l1VqH9mslM=

DevMode Function (Removed)

Note: The Devmode function has been removed in this version because of uselessness.


Changelog

Version 0.0.6

  • Removed Devmode Function.
  • Added Enhanced Loading Bar
  • Added Key Generator

Real Code Example:

import sys
import time
from cryptography.fernet import Fernet

# Color Stuff
def loading_bar(steps=50, bar_length=50, delay_per_step=0.1, message="Loading... ", color=None):
    # Define basic ANSI color codes
    colors = {
        "r": "\033[91m",
        "g": "\033[92m",
        "y": "\033[93m",
        "b": "\033[94m",
        "m": "\033[95m",
        "c": "\033[96m",
        "w": "\033[97m",
        "refresh": "\033[0m"
    }

    # Apply color if specified
    start_color = colors.get(color, "")  # Get the color code or empty string if invalid
    reset_color = colors["refresh"]

    for current_step in range(steps + 1):
        # Calculate progress
        filled_length = int((current_step / steps) * bar_length)
        bar = f"[{'=' * filled_length}{' ' * (bar_length - filled_length)}]"

        # Print the bar on the same line without adding extra lines
        sys.stdout.write(f"\r{start_color}{message}{bar} {current_step}/{steps}{reset_color}")
        sys.stdout.flush()
        time.sleep(delay_per_step)

    # Clear and overwrite the bar with a "Complete!" message
    sys.stdout.write("\n")

def enhancedloading_bar(steps=50, bar_length=50, delay_per_step=0.1, message="Loading...", color=None):
    """
    Displays a horizontal loading bar with estimated time remaining.
    """
    # Define basic ANSI color codes
    colors = {
        "r": "\033[91m",
        "g": "\033[92m",
        "y": "\033[93m",
        "b": "\033[94m",
        "m": "\033[95m",
        "c": "\033[96m",
        "w": "\033[97m",
        "refresh": "\033[0m"
    }

    # Apply color if specified
    start_color = colors.get(color, "")
    reset_color = colors["refresh"]

    start_time = time.time()

    for current_step in range(steps + 1):
        # Calculate progress
        filled_length = int((current_step / steps) * bar_length)
        bar = f"[{'=' * filled_length}{' ' * (bar_length - filled_length)}]"

        elapsed_time = time.time() - start_time
        eta = (elapsed_time / (current_step + 1)) * (steps - current_step) if current_step > 0 else 0

        # Print the bar with ETA
        sys.stdout.write(f"\r{start_color}{message}{bar} {current_step}/{steps} ETA: {eta:.1f}s{reset_color}")
        sys.stdout.flush()
        time.sleep(delay_per_step)

    sys.stdout.write("\nDone!\n")

def new_line():
    print("\n")

def colored_text(text, color):
    colors = {
        "red": "\033[91m",
        "green": "\033[92m",
        "yellow": "\033[93m",
        "blue": "\033[94m",
        "magenta": "\033[95m",
        "cyan": "\033[96m",
        "white": "\033[97m",
        "reset": "\033[0m"
    }

    color_code = colors.get(color.lower(), colors["white"])
    print(f"{color_code}{text}{colors['reset']}")

def cls():
    print("\033[H\033[J")

def generatekey():
    return Fernet.generate_key().decode()  # Decoding the byte key to a string

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ultraezloadingbar-0.0.1.1.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ultraezloadingbar-0.0.1.1-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file ultraezloadingbar-0.0.1.1.tar.gz.

File metadata

  • Download URL: ultraezloadingbar-0.0.1.1.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for ultraezloadingbar-0.0.1.1.tar.gz
Algorithm Hash digest
SHA256 1610284c5e36a365e28ebbfd43276bb3a564f243f12048d07695bd6b8f5ef2af
MD5 9b296647f5ae2dc630fff916663bf847
BLAKE2b-256 bcd6689515f2156a346db7d7ffbdee1b589ee25a5307accf4313ec30b71af201

See more details on using hashes here.

File details

Details for the file ultraezloadingbar-0.0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for ultraezloadingbar-0.0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 745cd6ef965c79b83ce288227c3b84be8e2d8b1f2efc2b2dee2f3dcc8c22fe17
MD5 01b8ce8545cff3a280d4c8fd4c6e222a
BLAKE2b-256 9143ffcfa7ee91ed2901127030aa659cb8081038251b4eef31b21aa196ee00b2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page