Skip to main content

A flexible terminal text styling utility for color, background, and custom formatting options.

Project description

styled_print

A simple utility for printing styled text to the terminal with color, background, and other styles.

Installation

You can install styled_print via pip:

pip install styled_print

Usage

The styled_print function allows you to print styled text in the terminal. It accepts a string and an options dictionary to customize the output.

Function Signature:

styled_print(string, options)

Parameters:

  • string (str): The text you want to print.
  • options (dict): A dictionary containing styling options.
    The dictionary can include:
    • color (str, optional): The text color.
      e.g., "red", "blue", "green", etc.
    • styles (list, optional): A list of text styles.
      Possible values: ["bold"], ["underline"], ["italic"], etc.
    • bg_color (str, optional): The background color.
      e.g., "on_white", "on_red", etc.
    • uppercase (bool, optional): If True, converts the text to uppercase.
    • lowercase (bool, optional): If True, converts the text to lowercase.
    • align (str, optional): Align the text.
      Possible values: "left", "center", "right". Default is "left".
    • padding (int, optional): Number of spaces to add around the text for padding. Default is 0.
    • border (bool, optional): If True, prints the text with a border.

Example Usage:

from styled_print import styled_print

# Print bold red text on a white background
styled_print("Hello", {
    "color": "red",
    "styles": ["bold"],
    "bg_color": "on_white"
})

# Print uppercase text with padding and border
styled_print("Hello World", {
    "color": "blue",
    "styles": ["underline"],
    "bg_color": "on_yellow",
    "uppercase": True,
    "padding": 2,
    "border": True
})

# Print center-aligned, green italic text
styled_print("Centered Text", {
    "color": "green",
    "styles": ["italic"],
    "align": "center"
})

Example Output:

For the example:

styled_print("Hello", {
    "color": "red",
    "styles": ["bold"],
    "bg_color": "on_white"
})

You will get output like this:

Hello  (in bold red on white background)

For the second example with padding and a border, the output will look like this:

--------------------------------------------------
|     HELLO WORLD     |
--------------------------------------------------

Customization Options:

  • Color: The available text colors are the basic colors supported by termcolor (red, blue, green, etc.).
  • Text Styles: You can apply multiple styles to text, such as:
    • "bold": Makes the text bold.
    • "underline": Underlines the text.
    • "italic": Italicizes the text (not all terminals support this).
  • Background Color: Background color options are also from termcolor (on_white, on_red, etc.).
  • Alignment: You can align text to the "left", "center", or "right".
  • Padding: Adds a padding (space) around the text for visual clarity.
  • Border: Wraps the text with a simple ASCII border.

Example Output:

  • Uppercase Example:

    styled_print("hello", {"uppercase": True})
    

    Output:

    HELLO
    
  • Text with Padding:

    styled_print("padded text", {"padding": 4})
    

    Output:

    "    padded text    "
    
  • Text with Border:

    styled_print("bordered text", {"border": True})
    

    Output:

    ---------------------------
    | bordered text          |
    ---------------------------
    

License

This package 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

styled_print-0.1.1.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

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

styled_print-0.1.1-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file styled_print-0.1.1.tar.gz.

File metadata

  • Download URL: styled_print-0.1.1.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for styled_print-0.1.1.tar.gz
Algorithm Hash digest
SHA256 22a484a2effdb6b8a52d4ecbb83b4b6d8f69862842820274f3dbf3e81f0c85b9
MD5 f90f19270fe5379973580b61ce9c5fba
BLAKE2b-256 d8f251cdfecaf42aa9ca8b947d1ee6ec09163b5309ff5d6ff2fe601933f35aab

See more details on using hashes here.

File details

Details for the file styled_print-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: styled_print-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for styled_print-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d1804615131835f6760fd69025052723f54d6fa3fdb40c475b7aab665a1d4aaf
MD5 9aeb534ef6e3b304f4063833aa2752dd
BLAKE2b-256 a1bb1d51564ec164894236b27000c1ac504431c7b6eef1fa278f89e58d14b157

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