Created
June 11, 2019 21:38
-
-
Save Anthex/dc17a00836192ef1e0d9d43e3f6d687f to your computer and use it in GitHub Desktop.
Easiest way to quickly format your terminal output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
#some ANSI output formatters | |
class output: | |
NORMAL = '\033[39;37;40m' | |
RED = '\033[0;31;40m' | |
GREEN = '\033[1;32;40m' | |
TEAL = '\033[38;5;51m' | |
ORANGE = '\033[38;5;229m' | |
HIGHLIGHTED = '\033[03;30;47m' | |
CLEAR = chr(27)+'[2j\033c\x1bc' | |
SLOWBLINK = '\033[5;37;40m' | |
#printf function to use in lieu of print() | |
def printf(*argv, end='\n'): | |
for arg in argv: | |
print(str(arg).format(output=output), end='') | |
print(output.NORMAL, end='') | |
print(end, end='') | |
sys.stdout.flush() | |
#usage example | |
printf("{output.RED} green text, {output.GREEN} green text and {output.SLOWBLINK}blinking output if your terminal supports it") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment