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.7.tar.gz (7.7 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.7-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for stv_utils-0.0.7.tar.gz
Algorithm Hash digest
SHA256 740bbdaf867d08e0f7f150190620fd663978f51f1388177597e03d5bae943655
MD5 603824f8e53a23fbb022eb4aaf36b5d1
BLAKE2b-256 58443b6e7a7069e4b80be4e23689604bafab5fdc11369bca1f3ff7fa44c0fd1a

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for stv_utils-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 7daa051ce65a42b5f2e9207c9fed2f6823a74301b8cb9d2a6cbe4b1cfc05216e
MD5 526f800df5e98bcd83918b54c18a08ef
BLAKE2b-256 97356adeefe4d7a4766dde0cba4cca7b68c4bb9ee47b887254adc00992c3517f

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