Tone Text
Output colored text to the terminal using Python
Setup and Installation
Using pip
pip install tonetext
Or upgrade current version:
pip install --upgrade tonetext
Example
Foreground
from tonetext import colored
print(colored("This is red text", color="red"))
Or
from tonetext import cprint
cprint("Hello there", color="green")
Foreground and Background
from tonetext import colored
print(colored("Green on white", color="green", on_color="white"))
Or
from tonetext import cprint
cprint("Red on black", color="red", on_color="black")
Styling
underline & italic are not supported on windows
from tonetext import italic, underline, bold
print(italic("This is italic"))
print(underline("This is underlined"))
print(bold("This is bold"))
Styling with Foreground and Background
from tonetext import colored, italic, underline, bold
print(
underline("This is red on white",
color="red",
on_color="white")
)
print(
italic("This is italic",
color="green")
)
Specific Use Cases
These method prints by default & return None
from tonetext import warn, error, info, success
warn("This is warning")
info("This is to inform")
success("Success", strong=False)
error("Error: File Missing")
Horizontal Line (width equal to terminal width)
from tonetext import line
line()
line(text="Hello")
line(text="Hello", color="red")
help(line)
Available Colors and Styles
Black | Grey |
Red | Red |
Green | Green |
Yellow | Yellow |
Blue | Blue |
Magenta | Magenta |
Cyan | Cyan |
White | White |
colored | text, color, on_color | Colored text |
italic | text, color, on_color | Italic colored text |
underline | text, color, on_color | Underlined colored text |
bold | text, color, on_color | Bold colored text |
warn | text | Yellow Bold Warning text |
error | text | Red Bold Error text |
info | text | Blue Bold Information text |
success | text | Green Bold Success text |