pyppin.text.tty¶
Tools to do TTY color formatting in print() statements.
Functions
|
Generate text for print() statements with color controls in it. |
Classes
|
An enumeration. |
- pyppin.text.tty.tty(*codes: ~pyppin.text.tty.TTY, text: ~typing.Optional[str] = None, file: ~typing.Any = <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>) str [source]¶
Generate text for print() statements with color controls in it.
To use it, simply put commands into a string you’re printing:
print(f"{tty(TTY.RED)}Some text{tty(TTY.RESET)}")
You can set multiple properties at a time, like bright + red. Don’t forget to RESET when you want the effect to end, or it will continue to affect text even into succeeding print statements! If you want to wrap an entire string in an effect, we’ll help you out:
print(tty(TTY.RED, TTY.BRIGHT, text="Some text"))
If you’re using this in any function other than print(), you might want to pass the “file” attribute to tty, which lets the function figure out if the thing you’re writing to supports VT100 color control codes at all. (e.g., normal text files don’t!) If it doesn’t, it’ll suppress the codes for you.
- Parameters
codes – The list of display attributes to turn on
file – The file you’re writing to
text – If given, format the entire string by wrapping it as <codes><text><reset>; the output of this function can be printed directly without having to worry about RESETing afterwards. By default, this function just returns <codes> to turn on the behavior.