Skip to main content

ConsoleMasterPy

ConsoleMasterPy is a Python library that simplifies console manipulation on Windows systems. It provides functionalities for changing console colors, hiding/showing the cursor, setting console window size, and more.

Installation

You can install ConsoleMasterPy using pip:

pip install ConsoleMasterPy

Usage

from ConsoleMasterPy import ConsoleMaster

Create a new console window

console = ConsoleMaster(title="My Console", font_size=17, window_width=30, window_height=25)

Change console colors

console.change_console_color(background_color=(0, 0, 0), foreground_color=(255, 255, 255))

Print with custom colors

console.print_with_color(rgb_background=(0, 0, 0), rgb_foreground=(255, 255, 255), element_to_print="Hello, World!")

Change console window size

console.change_windows_size(width=40, height=30)

Hide the cursor

console.hide_cursor()

Pause execution until user input

console.pause()

Go to specified position (x, y) in the console window

console.go_xy(x=10, y=5)

Change pixel size of the console font

console.change_pixel_size(size=20)

Clean a specified zone in the console window

console.clean_zone(x_coord_init=5, y_coord_init=5, x_coord_end=15, y_coord_end=10)

Clean the entire console window

console.clean_windows()

Pause execution until user input

console.pause()

Additional Functions

generate_name()

This function generates a random name with a mix of vowels and consonants.

from ConsoleMasterPy import generate_name

name = generate_name()
print(name)

exception_handler Function

The exception_handler function is a decorator used to handle exceptions within functions. It catches any exceptions that occur during the execution of the decorated function and logs the error message, along with a timestamp, to a file named log.txt. This decorator ensures that the program can continue running smoothly even if an exception occurs, providing better error handling and debugging.

Parameters

  • func: The function to be decorated with exception handling.

Example Usage

@exception_handler
def my_function():
    # Code that might raise an exception
    pass

Example usage - Game of Life of John Horton Conway

from ConsoleMasterPy import ConsoleMaster, exception_handler
import random
from time import sleep

def copy_matrix(matrix):
    return [row[:] for row in matrix]

width, height = 35, 35
console_manager = ConsoleMaster("GAME OF LIFE", 13, width, height)

@exception_handler
def main():
    generation_counter = 0
    
    while True:
        if generation_counter == 0:
            current_matrix = [[0 for x in range(width)] for y in range(height)]
            next_matrix = copy_matrix(current_matrix)
            cell_color = [random.randint(0, 255) for _ in range(3)]

            live_cell_rules = [random.randint(0, 1) for _ in range(9)]
            birth_rules = [random.randint(0, 1) for _ in range(9)]

            for x in range(width):
                next_matrix[x][0] = 0
                next_matrix[x][height - 1] = 0
                next_matrix[x][1] = 1
                next_matrix[x][height - 2] = 1

            for y in range(height):
                next_matrix[0][y] = 0
                next_matrix[width - 1][y] = 0
                next_matrix[1][y] = 1
                next_matrix[width - 2][y] = 1

            for x in range(1, width - 1):
                for y in range(1, height - 1):
                    cell_value = next_matrix[x][y]
                    console_manager.go_xy(x, y)
                    color = cell_color if cell_value else [0, 0, 0]
                    console_manager.print_with_color(color, [0, 0, 0], " ")
            generation_counter = 300

        generation_counter -= 1

        current_matrix = copy_matrix(next_matrix)
        for x in range(1, width - 1):
            for y in range(1, height - 1):
                neighbors = [(x + i, y + j) for i in range(-1, 2) for j in range(-1, 2) if not (i == 0 and j == 0)]
                count = sum(1 for i, j in neighbors if 0 <= i < width and 0 <= j < height and current_matrix[i][j] == 1)

                if current_matrix[x][y] == 1:
                    if not live_cell_rules[count]:
                        next_matrix[x][y] = 0
                        console_manager.go_xy(x, y)
                        console_manager.print_with_color([0, 0, 0], [0, 0, 0], " ")
                    else:
                        next_matrix[x][y] = 1
                else:
                    if birth_rules[count]:
                        next_matrix[x][y] = 1
                        console_manager.go_xy(x, y)
                        console_manager.print_with_color(cell_color, [0, 0, 0], " ")
                    else:
                        next_matrix[x][y] = 0
        sleep(0.05)

main()

License

ConsoleMasterPy is licensed under the MIT.

Metadata

Release files for ConsoleMasterPy 1.0.7.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ConsoleMasterPy 1.0.7.1
File Size Uploaded
ConsoleMasterPy-1.0.7.1.tar.gz 5.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ConsoleMasterPy 1.0.7.1
File Interpreter ABI Platform
ConsoleMasterPy-1.0.7.1-py3-none-any.whl Python 3 none any Details

Total release size: 10.2 kB

Release files / ConsoleMasterPy-1.0.7.1.tar.gz

Download URL ConsoleMasterPy-1.0.7.1.tar.gz
Size 5.0 kB
Tags Source
SHA-256 checksum
How to use checksums
47b920bd7f3e3e1ff154b4ec66379e0f7f1426ac704467f5f9b8d64ce711819d
BLAKE2b-256 checksum
How to use checksums
382a231656b0f470fe8bab219f7c5cf1d29f95f4d8084a3f286b6f8c33421cc4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release files / ConsoleMasterPy-1.0.7.1-py3-none-any.whl

Download URL ConsoleMasterPy-1.0.7.1-py3-none-any.whl
Size 5.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
118062b1cd00350b969dbb8fc94440d23ad5e091a02ce7eb5cb72c567ac2db20
BLAKE2b-256 checksum
How to use checksums
d42c86f701fbfcb2edf47e8e38397e1440b7015b842212755324fb7ebb3de4fb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release history Release notifications | RSS feed

This release

1.0.7.1 This release

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page