Skip to main content

Some commonly used tool functions.

Project description

stv_utils - Python Utility Library

Python Version License Version

stv_utils is a Python utility library containing commonly used functions, particularly useful for projects requiring terminal output beautification, system environment detection, and console operations.

Features

🎨 Terminal Colors & Styles

  • Generate ANSI escape codes
  • Control foreground, background colors and text styles
  • Includes normal and bright versions of colors

🌈 Colorized Output

  • Enhanced print function supports hex color codes
  • Automatically converts hex colors to the closest 256-color ANSI codes
  • Maintains all parameters of native print function

🎭 Output Control

  • Colorize output based on specific string prefixes
  • Suppress output of specific lines by prefix
  • Decorators simplify output control

🖥️ System Utilities

  • Detect Chinese language environment
  • Identify operating system type
  • Check if running in IDLE environment
  • Cross-platform console clearing function

Installation

pip install stv_utils

Quick Start

Basic Color Control

from stv_utils import color

# Get color and style dictionaries
fg, bg, styles = color()

print(f"{fg['red']}Red text{styles['reset_all']}")
print(f"{bg['blue']}Blue background{styles['reset_all']}")
print(f"{styles['bold']}Bold text{styles['reset_all']}")

Colorized Output

from stv_utils import print

# Using hex color codes
print(";#ff0000;This is red text")
print(";#00ff00;This is green text")
print(";#0000ff;This is blue text")

Output Control

from stv_utils import colorize, suppress_print

@colorize(color_code="\033[93m")  # Yellow
def my_function():
    print("|> This line will be colored")
    print("This line remains default color")

@suppress_print(start_str="|>")
def my_quiet_function():
    print("|> This line will be suppressed")
    print("This line will display normally")

System Utilities

from stv_utils import is_ch, system_check, system_clear

# Detect Chinese environment
if is_ch():
    print("Chinese environment detected")

# Get OS information
print(f"Current system: {system_check(verbose=True)}")

# Clear screen
system_clear()

Module Overview

color.py

Provides ANSI escape sequence generation:

  • 8 basic colors (black, red, green, yellow, blue, magenta, cyan, white) and their bright versions
  • 9 text styles (bold, dim, italic, underline, blink, reverse, hidden, strikethrough, reset_all)

output.py

Extends Python's built-in print function to support hex color codes in ;#xxxxxx; format, automatically converting to the closest 256-color ANSI code.

output_control.py

Provides output control capabilities:

  • ColorizedOutput: Colorize text with specific prefixes
  • SuppressedOutput: Suppress text output with specific prefixes
  • colorize decorator: Simplify function output coloring
  • suppress_print decorator: Simplify function output suppression

system_utils.py

System utility functions:

  • is_ch(): Detect Chinese language environment
  • system_check(): Get operating system information
  • is_idle(): Check if running in IDLE environment
  • system_clear(): Cross-platform screen clearing function

Contributing

Contributions are welcome! Please submit issues or pull requests via GitHub: https://github.com/StarWindv/stv_utils

License

This project is licensed under the MIT License.

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

stv_utils-0.0.8.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

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

stv_utils-0.0.8-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file stv_utils-0.0.8.tar.gz.

File metadata

  • Download URL: stv_utils-0.0.8.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.6

File hashes

Hashes for stv_utils-0.0.8.tar.gz
Algorithm Hash digest
SHA256 fddda0ddb0ff0fc109206164a0b238649e8e6243cf4bc7f60a123be7aa2912ac
MD5 a131547e8016abd060972cf700585024
BLAKE2b-256 53d9caf387248ffd66c6b028752fe3c60dccbf60393aa8cbd74fb6df241366c6

See more details on using hashes here.

File details

Details for the file stv_utils-0.0.8-py3-none-any.whl.

File metadata

  • Download URL: stv_utils-0.0.8-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.6

File hashes

Hashes for stv_utils-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 2a92ac361d807032849a8f10a40db738e0185b7435273ae1a9ea4bc621539e36
MD5 02c2424e42d6e7a86e4e11b4abb5c18f
BLAKE2b-256 25bce3903340322370d311b1279929fdd582fdaa3ff8bbd8567d5642333fdec1

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