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.0.6.tar.gz (3.9 kB view details)

Uploaded Source

Built Distributions

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

ultraezloadingbar-0.0.0.6-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

UltraEZLoadingBar-0.0.0.6-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for ultraezloadingbar-0.0.0.6.tar.gz
Algorithm Hash digest
SHA256 970fab5c1392390de1ad98671ac08cff7175efdb464bb03061d07339a862e03f
MD5 e6d248fb5937b99da939f64c78019345
BLAKE2b-256 7314c4054a6f1e7a069c344c9ffe87930fe05a6961470828d339624f34944dc9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ultraezloadingbar-0.0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 108d78bb218a6366bb3131dd03fc3905be45d96f702f6061498910f6f8e329a5
MD5 b2b8121b7a77121e83e517943bac1634
BLAKE2b-256 d16a142237d74cc7cbccdb6ac250f03850da3801615c0120ad32e4d6461fb135

See more details on using hashes here.

File details

Details for the file UltraEZLoadingBar-0.0.0.6-py3-none-any.whl.

File metadata

File hashes

Hashes for UltraEZLoadingBar-0.0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 a4452b1e894063e396f54a43f9c47fd484b3fc60e3c3d997eef174534d86025c
MD5 2a56f4c79b74dad0c9a31f5d764e3304
BLAKE2b-256 b3d1e194973e7ff205913545ecd158d79ab3a90a624487bb9d4cabf74d0cfb5c

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