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.9.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.9-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for stv_utils-0.0.9.tar.gz
Algorithm Hash digest
SHA256 f80c28f3239b9b25f4cfcf390e26e53dbbed0de9acc560e52f4a88192e1ffb77
MD5 55ecf06a6ee93ba4b852f653b33e635c
BLAKE2b-256 bd42605b49b63046adfe71fae322f0b465cbbfaa1799038d8634ad652257bb89

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for stv_utils-0.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 cafdecca581fef4b8f553105738a013cab384ebcdbbb7efddcf9fa1b5b8bace4
MD5 ee565ac61fdacc1b5747edee8869b646
BLAKE2b-256 8226290c4304d27ed72a0dfaea2bdf9ded6fff99df21c16ca55f8aac5a8409c0

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